Hardware/HDD/SSDSandforce.cs
author sl
Sun, 03 Feb 2013 19:06:01 +0100
changeset 392 8af90fa0940f
parent 344 3145aadca3d2
permissions -rw-r--r--
Now fetching some of our Sound Graph DLL function pointers.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	Copyright (C) 2010 Paul Werelds
     9 	
    10 */
    11 
    12 using System.Collections.Generic;
    13 using OpenHardwareMonitor.Collections;
    14 
    15 namespace OpenHardwareMonitor.Hardware.HDD {
    16 
    17   [NamePrefix(""), RequireSmart(0xAB), RequireSmart(0xB1)]
    18   internal class SSDSandforce : AbstractHarddrive {
    19 
    20     private static readonly IEnumerable<SmartAttribute> smartAttributes =
    21       new List<SmartAttribute> {
    22       new SmartAttribute(0x01, SmartNames.RawReadErrorRate),
    23       new SmartAttribute(0x05, SmartNames.RetiredBlockCount, RawToInt),
    24       new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt),
    25       new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt),
    26       new SmartAttribute(0xAB, SmartNames.ProgramFailCount, RawToInt),
    27       new SmartAttribute(0xAC, SmartNames.EraseFailCount, RawToInt),
    28       new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt),
    29       new SmartAttribute(0xB1, SmartNames.WearRangeDelta, RawToInt),
    30       new SmartAttribute(0xB5, SmartNames.AlternativeProgramFailCount, RawToInt),
    31       new SmartAttribute(0xB6, SmartNames.AlternativeEraseFailCount, RawToInt),
    32       new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt),
    33       new SmartAttribute(0xC2, SmartNames.Temperature, 
    34         (byte[] raw, byte value, IReadOnlyArray<IParameter> p) 
    35           => { return value + (p == null ? 0 : p[0].Value); }, 
    36         SensorType.Temperature, 0, true, 
    37         new[] { new ParameterDescription("Offset [°C]", 
    38                   "Temperature offset of the thermal sensor.\n" + 
    39                   "Temperature = Value + Offset.", 0) }), 
    40       new SmartAttribute(0xC3, SmartNames.UnrecoverableEcc), 
    41       new SmartAttribute(0xC4, SmartNames.ReallocationEventCount, RawToInt),
    42       new SmartAttribute(0xE7, SmartNames.RemainingLife, null, 
    43         SensorType.Level, 0),
    44       new SmartAttribute(0xE9, SmartNames.ControllerWritesToNAND, RawToInt,
    45         SensorType.Data, 0),
    46       new SmartAttribute(0xEA, SmartNames.HostWritesToController, RawToInt, 
    47         SensorType.Data, 1),
    48       new SmartAttribute(0xF1, SmartNames.HostWrites, RawToInt, 
    49         SensorType.Data, 1),
    50       new SmartAttribute(0xF2, SmartNames.HostReads, RawToInt, 
    51         SensorType.Data, 2)
    52     };
    53 
    54     private Sensor writeAmplification;
    55 
    56     public SSDSandforce(ISmart smart, string name, string firmwareRevision, 
    57       int index, ISettings settings) 
    58       : base(smart, name, firmwareRevision,  index, smartAttributes, settings) 
    59     {
    60       this.writeAmplification = new Sensor("Write Amplification", 1, 
    61         SensorType.Factor, this, settings);    
    62     }
    63 
    64     public override void UpdateAdditionalSensors(DriveAttributeValue[] values) {
    65       float? controllerWritesToNAND = null;
    66       float? hostWritesToController = null;
    67       foreach (DriveAttributeValue value in values) {
    68         if (value.Identifier == 0xE9)
    69           controllerWritesToNAND = RawToInt(value.RawValue, value.AttrValue, null);
    70 
    71         if (value.Identifier == 0xEA)
    72           hostWritesToController = RawToInt(value.RawValue, value.AttrValue, null);
    73       }
    74       if (controllerWritesToNAND.HasValue && hostWritesToController.HasValue) {
    75         if (hostWritesToController.Value > 0)
    76           writeAmplification.Value =
    77             controllerWritesToNAND.Value / hostWritesToController.Value;
    78         else
    79           writeAmplification.Value = 0;
    80         ActivateSensor(writeAmplification);
    81       }
    82     }
    83   }
    84 }