Changeset 5266

Show
Ignore:
Timestamp:
05/28/08 09:26:11 (5 years ago)
Author:
khali
Message:

Cache the byte data reads. As we keep reading the same registers over
and over again in the detection functions, and SMBus can be slow,
caching results in a big performance boost. This closes ticket #2326.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5264 r5266  
    66                  Add SMSC EMC6D103 support 
    77                  Improve MAX6657, MAX6658, MAX6659 detection 
     8                  Cache the byte data reads (#2326) 
    89 
    9103.0.2 (2008-05-18) 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect

    r5264 r5266  
    4646######################### 
    4747 
     48use constant NO_CACHE => 1; 
    4849use vars qw(@pci_adapters @chip_ids $i2c_addresses_to_scan @superio_ids 
    49             @cpu_ids $revision); 
     50            @cpu_ids $revision @i2c_byte_cache); 
    5051 
    5152$revision = '$Revision$ ($Date$)'; 
     
    26902691{ 
    26912692  my ($file, $addr) = @_; 
     2693 
     2694  # Reset register data cache 
     2695  @i2c_byte_cache = (); 
     2696 
    26922697  $addr += 0; # Make sure it's a number not a string 
    26932698  ioctl $file, IOCTL_I2C_SLAVE, $addr or return 0; 
     
    27442749# $_[1]: Command byte (usually register number) 
    27452750# Returns: -1 on failure, the read byte on success. 
     2751# Read byte data values are cached by default. As we keep reading the 
     2752# same registers over and over again in the detection functions, and 
     2753# SMBus can be slow, caching results in a big performance boost. 
    27462754sub i2c_smbus_read_byte_data 
    27472755{ 
    2748   my ($file, $command) = @_; 
     2756  my ($file, $command, $nocache) = @_; 
    27492757  my @data; 
     2758  if (!$nocache && exists $i2c_byte_cache[$command]) { 
     2759    return $i2c_byte_cache[$command]; 
     2760  } 
    27502761  i2c_smbus_access $file, SMBUS_READ, $command, SMBUS_BYTE_DATA, \@data 
    27512762         or return -1; 
    2752   return $data[0]; 
     2763  return ($i2c_byte_cache[$command] = $data[0]); 
    27532764} 
    27542765 
     
    36333644  my $conf = i2c_smbus_read_byte_data($file, 0x01); 
    36343645 
    3635   my $hyst = i2c_smbus_read_byte_data($file, 0x02); 
     3646  my $hyst = i2c_smbus_read_byte_data($file, 0x02, NO_CACHE); 
    36363647  my $maxreg = $chip == 1 ? 0x0f : 0x07; 
    36373648  for $i (0x04 .. $maxreg) { 
    3638     return if i2c_smbus_read_byte_data($file, $i) != $hyst; 
    3639   } 
    3640  
    3641   my $os = i2c_smbus_read_byte_data($file, 0x03); 
     3649    return if i2c_smbus_read_byte_data($file, $i, NO_CACHE) != $hyst; 
     3650  } 
     3651 
     3652  my $os = i2c_smbus_read_byte_data($file, 0x03, NO_CACHE); 
    36423653  for $i (0x04 .. $maxreg) { 
    3643     return if i2c_smbus_read_byte_data($file, $i) != $os; 
     3654    return if i2c_smbus_read_byte_data($file, $i, NO_CACHE) != $os; 
    36443655  } 
    36453656 
     
    36973708  my $os = i2c_smbus_read_byte_data($file, 0x03); 
    36983709 
    3699   my $low = i2c_smbus_read_byte_data($file, 0x04); 
    3700   return if i2c_smbus_read_byte_data($file, 0x06) != $low; 
    3701   return if i2c_smbus_read_byte_data($file, 0x07) != $low; 
    3702  
    3703   my $high = i2c_smbus_read_byte_data($file, 0x05); 
    3704   return if i2c_smbus_read_byte_data($file, 0x06) != $high; 
    3705   return if i2c_smbus_read_byte_data($file, 0x07) != $high; 
     3710  my $low = i2c_smbus_read_byte_data($file, 0x04, NO_CACHE); 
     3711  return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $low; 
     3712  return if i2c_smbus_read_byte_data($file, 0x07, NO_CACHE) != $low; 
     3713 
     3714  my $high = i2c_smbus_read_byte_data($file, 0x05, NO_CACHE); 
     3715  return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $high; 
     3716  return if i2c_smbus_read_byte_data($file, 0x07, NO_CACHE) != $high; 
    37063717 
    37073718  for ($i = 8; $i <= 248; $i += 40) { 
     
    40544065{ 
    40554066  my ($file, $addr) = @_; 
    4056   my $mid = i2c_smbus_read_byte_data($file, 0xfe); 
    4057   my $cid = i2c_smbus_read_byte_data($file, 0xff); 
    4058   my $conf = i2c_smbus_read_byte_data($file, 0x03); 
     4067  my $mid = i2c_smbus_read_byte_data($file, 0xfe, NO_CACHE); 
     4068  my $cid = i2c_smbus_read_byte_data($file, 0xff, NO_CACHE); 
     4069  my $conf = i2c_smbus_read_byte_data($file, 0x03, NO_CACHE); 
    40594070 
    40604071  return if $mid != 0x4d;     # Maxim 
     
    40634074  return if $cid != 0x4d;     # No register, returns previous value 
    40644075 
    4065   my $rate = i2c_smbus_read_byte_data($file, 0x04); 
     4076  my $rate = i2c_smbus_read_byte_data($file, 0x04, NO_CACHE); 
    40664077  return if $rate > 0x09; 
    40674078 
    4068   $cid = i2c_smbus_read_byte_data($file, 0xff); 
    4069   $conf = i2c_smbus_read_byte_data($file, 0x03); 
     4079  $cid = i2c_smbus_read_byte_data($file, 0xff, NO_CACHE); 
     4080  $conf = i2c_smbus_read_byte_data($file, 0x03, NO_CACHE); 
    40704081  return if ($conf & 0x0f) != $rate; # No low nibble, 
    40714082                                     # returns previous low nibble