Changeset 5438

Show
Ignore:
Timestamp:
11/27/08 17:00:04 (4 years ago)
Author:
khali
Message:

Stop keeping track of the misdetected chips. Doing so needed very tricky
code, which isn't really needed anymode. For one thing, misdetections are
rare, as we have improved the detection functions quite a lot over the
years (and new chips are in general easier to detect reliably). It it
also unlikely that a driver which caused a misdetection will still be
loaded for another device on the same system. For another, this is really
the kernel drivers' job to make sure they will not bind to the wrong
device anyway (and we did indeed improve the drivers in this respect.)

More cleanups are certainly possible in this area. I have the feeling
that the data structures have not been wisely chosen. For efficient
confidence value comparisons, the detection data should be
address-centric rather than driver-centric.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect

    r5437 r5438  
    27422742#      being a reference to a list of 
    27432743#        references to hashes of type 'detect_data'; 
    2744 #    with field 'misdetected' 
    2745 #      being a reference to a list of 
    2746 #        references to hashes of type 'detect_data' 
    27472744 
    27482745# Type detect_data: 
     
    27732770{ 
    27742771  my ($chipdriver, $datahash) = @_; 
    2775   my ($i, $new_detected_ref, $new_misdetected_ref, $detected_ref, $misdetected_ref, 
    2776       $main_entry, $detected_entry, $put_in_detected, @hash_addrs, @entry_addrs, 
    2777       $do_not_add); 
     2772  my ($i, $new_detected_ref, $detected_ref, 
     2773      $main_entry, $detected_entry, $put_in_detected, @hash_addrs, @entry_addrs); 
    27782774 
    27792775  # First determine where the hash has to be added. 
     
    27832779  if ($i == @chips_detected) { 
    27842780    push @chips_detected, { driver => $chipdriver, 
    2785                             detected => [], 
    2786                             misdetected => [] }; 
     2781                            detected => [] }; 
    27872782  } 
    27882783  $new_detected_ref = $chips_detected[$i]->{detected}; 
    2789   $new_misdetected_ref = $chips_detected[$i]->{misdetected}; 
    2790  
    2791   # Find out whether our new entry should go into the detected or the 
    2792   # misdetected list. We compare all i2c addresses; if at least one matches, 
    2793   # but our conf value is lower, we assume this is a misdetect. 
     2784 
     2785  # Find out whether our new entry should go into the detected list 
     2786  # or not. We compare all i2c addresses; if at least one matches, 
     2787  # but our confidence value is lower, we assume this is a misdetection, 
     2788  # in which case we simply discard our new entry. 
    27942789  @hash_addrs = ($datahash->{i2c_addr}); 
    27952790  push @hash_addrs, @{$datahash->{i2c_sub_addrs}} 
    27962791       if exists $datahash->{i2c_sub_addrs}; 
    27972792  $put_in_detected = 1; 
    2798   $do_not_add = 0; 
    27992793  FIND_LOOP: 
    28002794  foreach $main_entry (@chips_detected) { 
     
    28082802          $put_in_detected = 0; 
    28092803        } 
    2810         if ($chipdriver eq $main_entry->{driver}) { 
    2811           $do_not_add = 1; 
    2812         } 
    28132804        last FIND_LOOP; 
    28142805      } 
     
    28172808 
    28182809  if ($put_in_detected) { 
    2819     # Here, we move all entries from detected to misdetected which 
     2810    # Here, we discard all entries which 
    28202811    # match at least in one main or sub address. This may not be the 
    28212812    # best idea to do, as it may remove detections without replacing 
    28222813    # them with second-best ones. Too bad. 
    2823     # (Khali 2003-09-13) If the driver is the same, the "misdetected" 
    2824     # entry is simply deleted; failing to do so cause the configuration 
    2825     # lines generated later to look very confusing (the driver will 
    2826     # be told to ignore valid addresses). 
    2827     @hash_addrs = ($datahash->{i2c_addr}); 
    2828     push @hash_addrs, @{$datahash->{i2c_sub_addrs}} 
    2829          if exists $datahash->{i2c_sub_addrs}; 
    28302814    foreach $main_entry (@chips_detected) { 
    28312815      $detected_ref = $main_entry->{detected}; 
    2832       $misdetected_ref = $main_entry->{misdetected}; 
    28332816      for ($i = @$detected_ref-1; $i >=0; $i--) { 
    28342817        @entry_addrs = ($detected_ref->[$i]->{i2c_addr}); 
     
    28372820        if ($detected_ref->[$i]->{i2c_devnr} == $datahash->{i2c_devnr} and 
    28382821            any_list_match(\@entry_addrs, \@hash_addrs)) { 
    2839           push @$misdetected_ref, $detected_ref->[$i] 
    2840             unless $chipdriver eq $main_entry->{driver}; 
    28412822          splice @$detected_ref, $i, 1; 
    28422823        } 
     
    28462827    # Now add the new entry to detected 
    28472828    push @$new_detected_ref, $datahash; 
    2848   } else { 
    2849     # No hard work here 
    2850     push @$new_misdetected_ref, $datahash 
    2851       unless $do_not_add; 
    28522829  } 
    28532830} 
     
    28622839{ 
    28632840  my ($alias_detect, $chipdriver, $datahash) = @_; 
    2864   my ($i, $new_detected_ref, $new_misdetected_ref, $detected_ref, $misdetected_ref, 
    2865       $main_entry, $isalias); 
     2841  my ($i, $new_detected_ref, $detected_ref, $main_entry, $isalias); 
    28662842 
    28672843  # First determine where the hash has to be added. 
     
    28722848  if ($i == @chips_detected) { 
    28732849    push @chips_detected, { driver => $chipdriver, 
    2874                             detected => [], 
    2875                             misdetected => [] }; 
     2850                            detected => [] }; 
    28762851  } 
    28772852  $new_detected_ref = $chips_detected[$i]->{detected}; 
    2878   $new_misdetected_ref = $chips_detected[$i]->{misdetected}; 
    28792853 
    28802854  # Now, we are looking for aliases. An alias can only be the same chiptype. 
    2881   # If an alias is found in the misdetected list, we add the new information 
    2882   # and terminate this function. If it is found in the detected list, we 
     2855  # If it is found in the detected list, we 
    28832856  # still have to check whether another chip has claimed this ISA address. 
    28842857  # So we remove the old entry from the detected list and put it in datahash. 
    2885  
    2886   # Misdetected alias detection: 
    2887   for ($i = 0; $i < @$new_misdetected_ref; $i++) { 
    2888     if (exists $new_misdetected_ref->[$i]->{i2c_addr} and 
    2889         not exists $new_misdetected_ref->[$i]->{isa_addr} and 
    2890         defined $alias_detect and 
    2891         $new_misdetected_ref->[$i]->{chipname} eq $datahash->{chipname}) { 
    2892       open(local *FILE, "$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}") or 
    2893         print("Can't open $dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), 
    2894         next; 
    2895       binmode(FILE); 
    2896       i2c_set_slave_addr(\*FILE, $new_misdetected_ref->[$i]->{i2c_addr}) or 
    2897            print("Can't set I2C address for ", 
    2898                  "$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), 
    2899            next; 
    2900       if (&$alias_detect ($datahash->{isa_addr}, \*FILE, 
    2901                           $new_misdetected_ref->[$i]->{i2c_addr})) { 
    2902         $new_misdetected_ref->[$i]->{isa_addr} = $datahash->{isa_addr}; 
    2903         return $new_misdetected_ref->[$i]; 
    2904       } 
    2905     } 
    2906   } 
    2907  
    2908   # Detected alias detection: 
    29092858  for ($i = 0; $i < @$new_detected_ref; $i++) { 
    29102859    if (exists $new_detected_ref->[$i]->{i2c_addr} and 
     
    29302879  } 
    29312880 
    2932  
    2933   # Find out whether our new entry should go into the detected or the 
    2934   # misdetected list. We only compare main isa_addr here, of course. 
    2935   # (Khali 2004-05-12) If the driver is the same, the "misdetected" 
    2936   # entry is simply deleted; same we do for I2C chips. 
     2881  # Find out whether our new entry should go into the detected list 
     2882  # or not. We only compare main isa_addr here, of course. 
    29372883  foreach $main_entry (@chips_detected) { 
    29382884    $detected_ref = $main_entry->{detected}; 
    2939     $misdetected_ref = $main_entry->{misdetected}; 
    29402885    for ($i = 0; $i < @{$main_entry->{detected}}; $i++) { 
    29412886      if (exists $detected_ref->[$i]->{isa_addr} and 
    29422887          exists $datahash->{isa_addr} and 
    29432888          $detected_ref->[$i]->{isa_addr} == $datahash->{isa_addr}) { 
    2944         if ($detected_ref->[$i]->{conf} >= $datahash->{conf}) { 
    2945           push @$new_misdetected_ref, $datahash 
    2946             unless $main_entry->{driver} eq $chipdriver; 
    2947         } else { 
    2948           push @$misdetected_ref, $detected_ref->[$i] 
    2949             unless $main_entry->{driver} eq $chipdriver; 
     2889        if ($detected_ref->[$i]->{conf} < $datahash->{conf}) { 
    29502890          splice @$detected_ref, $i, 1; 
    29512891          push @$new_detected_ref, $datahash; 
     
    52855225    } 
    52865226 
    5287     # Handle misdetects 
    5288     foreach $detection (@{$chip->{misdetected}}) { 
    5289       push @optionlist, $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}, 
    5290                        $detection->{i2c_addr} 
    5291            if exists $detection->{i2c_addr} and 
    5292               exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}; 
    5293       push @optionlist, -1, $detection->{isa_addr} 
    5294            if exists $detection->{isa_addr}; 
    5295     } 
    5296  
    52975227    # Handle aliases 
    52985228    # As of kernel 2.6.28, alias detection is handled by kernel drivers 
     
    54505380  my ($chip, $data); 
    54515381  foreach $chip (@chips_detected) { 
    5452     print "\nDriver `$chip->{driver}' "; 
    5453     if (@{$chip->{detected}}) { 
    5454       if (@{$chip->{misdetected}}) { 
    5455         print "(should be inserted but causes problems):\n"; 
    5456       } else { 
    5457         print "(should be inserted):\n"; 
    5458       } 
    5459     } else { 
    5460       if (@{$chip->{misdetected}}) { 
    5461         print "(may not be inserted):\n"; 
    5462       } else { 
    5463         print "(should not be inserted, but is harmless):\n"; 
    5464       } 
    5465     } 
    5466     if (@{$chip->{detected}}) { 
    5467       print "  Detects correctly:\n"; 
    5468       print_chips_report($chip->{detected}); 
    5469     } 
    5470     if (@{$chip->{misdetected}}) { 
    5471       print "  Misdetects:\n"; 
    5472       print_chips_report($chip->{misdetected}); 
    5473     } 
     5382    next unless @{$chip->{detected}}; 
     5383    print "\nDriver `$chip->{driver}':\n"; 
     5384    print_chips_report($chip->{detected}); 
    54745385  } 
    54755386  print "\n";