RoboBlog

19.05.2012

Nochmal Linux + Canon Powershot SX 130

Filed under: Allgemein — Tags: , — Thomas @ 10:05

Ich hatte ja schon mal kurz gtkam erwähnt um an die Dateien der Kamera zu kommen. Siehe [1]
Nun ist es so, wenn man eine 2GB Datei (HD Videos) laden will, erst mal 2GB Speicher reserviert werden. Leider hat nicht jeder 2GB am Stück frei. Wenn man die Datei überhaupt laden kann, kann es sehr sehr lange dauern (SWAP).

Warum ist das so? Ich habe mich auf die Suche gemacht.
Erstmal den Code von gtkam angesehen. Shit, ist das ein Kraut und Rüben Salat. Da blickt ja kein Mensch durch. Alles nur hingeklatsch. Hauptsache die GUI ist benutzbar und stürzt nicht allzu oft ab. Warum wohl nutze ich wenn möglich Konsolenprogramme.

Aber das bringt auch nichts, wenn die dazugehörige lib (libgphoto2) genauso bescheuert aufgebaut, programmiert und rar dokumentiert ist. Sicher, das ist alles kompliziert und so. Aber genau deswegen sollte man seine Sache gut machen.

Wir sind uns sicher einig, dass das Schreiber einer GUI längst nicht so kompliziert ist, als eine Kamera über USB anzuzapfen, wenn man keine Doku hat wie das geht. Genauso spiegelt sich das auch im Code wird. Der GUI Teil ist miserabel. Aber die Codezeilen, die direkt mit der Kamera reden, die sind gut.
Ein Lob an die Programmierer der Dateien libgphoto2-2.4.14/camlibs/canon/* Es gibt wohl kaum etwas komplizierteres als einer Kamera eine Handvoll Bytes vorzuwerfen, und sie liefert einem die gewünschten Daten.
Auch wenn ich mir nicht mal die Mühe gemacht habe den Code gut nachzuvollziehen, ich habe sofort gesehen wo mein Problem mit dem RAM ist. Und es ist sogar dokumentiert!

usb.c Zeile 1715

...
 * It calls #canon_usb_dialogue(), if it gets a good response it will malloc()
 * memory and read the entire returned data into this malloc'd memory and store
 * a pointer to the malloc'd memory in 'data'
...

...
while (bytes_received < total_data_size) {
...
bytes_read = gp_port_read (camera->port, (char *)*data + bytes_received, read_bytes);

So wie ich das sehe ist es sehr wohl möglich die Daten stückweise von der Kamera zu bekommen. Man hat die Möglichkeit einfach nur nicht vorgesehen.
Es ist nicht so einfach diese Funktion durch all die Abstraktionsebenen durchzuschleusen. Der Kamera spezifische Code muss es können. Dann die Lib. Und die GUI… die nicht.

Aber das nachträglich einzubauen halte ich für unmöglich. Man muss ja ALLES umbauen. Nun, niemand trifft die Schuld. Als man die ersten Codezeilen vor 10 Jahren oder so geschrieben hat, da hat man nicht dran gedacht. Man kann ja nicht an alles denken. Aber sein Code so zu strukturieren, dass nachträgliche Änderungen leicht möglich sind, das ist wohl erst in den letzten Jahren in Mode gekommen. Obwohl.. ich glaube nicht.

[1] http://roboblog.fatal-fury.de/?p=1220

08.05.2012

Eclipse Code ausdrucken

Filed under: Allgemein — Tags: , , — Thomas @ 17:05

Da die Print Möglichkeiten aus Eclipse heraus ziemlich bescheiden sind, habe ich mal etwas gesucht und das gefunden[1] :

a2ps --verbose --landscape --columns=2 --rows=1 --line-numbers=5 --tabsize=2 --pretty-print \
--highlight-level=normal --sides=duplex --pro=color FILENAME

[1] http://stackoverflow.com/questions/252975/how-to-print-out-code

01.05.2012

Festplattengehäuse Lüftungslöcher

Filed under: Allgemein — Thomas @ 10:05

Ich hab in mein Festplattengehäuse mal ein paar Lüftungslöcher gebohrt nur um festzustellen, dass sie garnicht benötigt werden.
Wie man auf dem Bild erkennen kann, strömt die Luft in den Schlitz zwischen den Gehäuseteilen. Na toll -_-

Unnötige Lüftungslöcher, der Rauch strömt durch den Schlitz

Unnötige Lüftungslöcher, der Rauch strömt durch den Schlitz

30.04.2012

S.M.A.R.T. Festplatten und Fehler

Filed under: Allgemein — Thomas @ 23:04

smartctl -a /dev/sdb
smartctl -t [short,offline,long] /dev/sdb
smartctl -l selftest

Karinas alte Festplatte (Backup Karina) Baujahr 2001 rum

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Barracuda 7200.7 and 7200.7 Plus family
Device Model:     ST3200021A
Serial Number:    3LJ091PD
Firmware Version: 3.01
User Capacity:    200,049,647,616 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   6
ATA Standard is:  ATA/ATAPI-6 T13 1410D revision 2
Local Time is:    Mon Apr 30 22:01:07 2012 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   063   051   006    Pre-fail  Always       -       146059820
  3 Spin_Up_Time            0x0003   096   096   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   098   098   020    Old_age   Always       -       2593
  5 Reallocated_Sector_Ct   0x0033   100   100   036    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   086   060   030    Pre-fail  Always       -       459228764
  9 Power_On_Hours          0x0032   088   088   000    Old_age   Always       -       10871
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   098   098   020    Old_age   Always       -       2629
194 Temperature_Celsius     0x0022   051   057   000    Old_age   Always       -       51
195 Hardware_ECC_Recovered  0x001a   063   051   000    Old_age   Always       -       146059820
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0000   100   253   000    Old_age   Offline      -       0
202 Data_Address_Mark_Errs  0x0032   100   253   000    Old_age   Always       -       0

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     10871         -
# 2  Short offline       Completed without error       00%     10870         -

Thomas Backup Baujahr JAN 2004

=== START OF INFORMATION SECTION ===
Model Family:     Hitachi Deskstar 7K250
Device Model:     HDS722512VLAT80
Serial Number:    VN343EC4C5NSAK
Firmware Version: V33OA60A
User Capacity:    123,522,416,640 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   6
ATA Standard is:  ATA/ATAPI-6 T13 1410D revision 3a
Local Time is:    Mon Apr 30 22:06:55 2012 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   100   100   060    Pre-fail  Always       -       0
  2 Throughput_Performance  0x0005   100   100   050    Pre-fail  Offline      -       0
  3 Spin_Up_Time            0x0007   143   143   024    Pre-fail  Always       -       227 (Average 190)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       618
  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       2
  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0005   100   100   020    Pre-fail  Offline      -       0
  9 Power_On_Hours          0x0012   098   098   000    Old_age   Always       -       18905
 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       617
192 Power-Off_Retract_Count 0x0032   099   099   050    Old_age   Always       -       1375
193 Load_Cycle_Count        0x0012   099   099   050    Old_age   Always       -       1375
194 Temperature_Celsius     0x0002   203   203   000    Old_age   Always       -       27 (Lifetime Min/Max 14/48)
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       2
197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       0

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     18905         -
# 2  Short offline       Completed without error       00%     18905         -

Thomas neue Platte? Baujahr JUN 2007

=== START OF INFORMATION SECTION ===
Model Family:     SAMSUNG SpinPoint P80 series
Device Model:     SAMSUNG SP1654N
Serial Number:    S0GEJDPP601158
Firmware Version: BV100-50
User Capacity:    160,041,885,696 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   7
ATA Standard is:  ATA/ATAPI-7 T13 1532D revision 4a
Local Time is:    Mon Apr 30 23:01:19 2012 CEST

Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   253   100   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0007   253   253   025    Pre-fail  Always       -       6016
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       35
  5 Reallocated_Sector_Ct   0x0033   253   253   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   253   253   051    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0025   253   253   015    Pre-fail  Offline      -       9980
  9 Power_On_Hours          0x0032   253   253   000    Old_age   Always       -       101
 10 Spin_Retry_Count        0x0033   253   253   051    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x0012   253   253   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       27
187 Reported_Uncorrect      0x0032   253   253   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   172   076   000    Old_age   Always       -       22
194 Temperature_Celsius     0x0022   172   076   000    Old_age   Always       -       22
195 Hardware_ECC_Recovered  0x001a   100   100   000    Old_age   Always       -       1600
196 Reallocated_Event_Count 0x0032   253   253   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0012   253   253   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   253   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       3
200 Multi_Zone_Error_Rate   0x000a   253   100   000    Old_age   Always       -       0
201 Soft_Read_Error_Rate    0x000a   253   100   000    Old_age   Always       -       0

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%       102         -
# 2  Short offline       Completed without error       00%       100         -

Karinas neue Backup Platte? Baujahr DEC 2004

=== START OF INFORMATION SECTION ===
Model Family:     Maxtor DiamondMax Plus 9 family
Device Model:     Maxtor 6Y160P0
Serial Number:    Y47NYMGE
Firmware Version: YAR41BW0
User Capacity:    163,928,604,672 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   7
ATA Standard is:  ATA/ATAPI-7 T13 1532D revision 0
Local Time is:    Tue May  1 08:45:58 2012 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  3 Spin_Up_Time            0x0027   205   204   063    Pre-fail  Always       -       12163
  4 Start_Stop_Count        0x0032   253   253   000    Old_age   Always       -       61
  5 Reallocated_Sector_Ct   0x0033   253   253   063    Pre-fail  Always       -       0
  6 Read_Channel_Margin     0x0001   253   253   100    Pre-fail  Offline      -       0
  7 Seek_Error_Rate         0x000a   253   252   000    Old_age   Always       -       0
  8 Seek_Time_Performance   0x0027   251   249   187    Pre-fail  Always       -       43532
  9 Power_On_Minutes        0x0032   234   234   000    Old_age   Always       -       233h+01m
 10 Spin_Retry_Count        0x002b   253   252   157    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x002b   253   252   223    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   253   253   000    Old_age   Always       -       120
192 Power-Off_Retract_Count 0x0032   253   253   000    Old_age   Always       -       0
193 Load_Cycle_Count        0x0032   253   253   000    Old_age   Always       -       0
194 Temperature_Celsius     0x0032   253   253   000    Old_age   Always       -       12
195 Hardware_ECC_Recovered  0x000a   253   252   000    Old_age   Always       -       2358
196 Reallocated_Event_Count 0x0008   253   253   000    Old_age   Offline      -       0
197 Current_Pending_Sector  0x0008   253   253   000    Old_age   Offline      -       0
198 Offline_Uncorrectable   0x0008   253   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0008   194   190   000    Old_age   Offline      -       15
200 Multi_Zone_Error_Rate   0x000a   253   252   000    Old_age   Always       -       0
201 Soft_Read_Error_Rate    0x000a   253   252   000    Old_age   Always       -       2
202 Data_Address_Mark_Errs  0x000a   253   252   000    Old_age   Always       -       0
203 Run_Out_Cancel          0x000b   253   252   180    Pre-fail  Always       -       2
204 Soft_ECC_Correction     0x000a   253   252   000    Old_age   Always       -       0
205 Thermal_Asperity_Rate   0x000a   253   252   000    Old_age   Always       -       0
207 Spin_High_Current       0x002a   253   252   000    Old_age   Always       -       0
208 Spin_Buzz               0x002a   253   252   000    Old_age   Always       -       0
209 Offline_Seek_Performnce 0x0024   197   189   000    Old_age   Offline      -       0
 99 Unknown_Attribute       0x0004   253   253   000    Old_age   Offline      -       0
100 Unknown_Attribute       0x0004   253   253   000    Old_age   Offline      -       0
101 Unknown_Attribute       0x0004   253   253   000    Old_age   Offline      -       0

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%      6362         -
# 2  Short offline       Completed without error       00%      6361         -

Thomas alte Laptop Festplatte

=== START OF INFORMATION SECTION ===
Model Family:     Toshiba 2.5" HDD series (80 GB and above)
Device Model:     TOSHIBA MK8032GSX
Serial Number:    36KS3781T
Firmware Version: AS112D
User Capacity:    78,518,522,880 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   6
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Tue May  1 09:34:17 2012 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   100   100   050    Pre-fail  Always       -       0
  2 Throughput_Performance  0x0004   100   100   000    Old_age   Offline      -       0
  3 Spin_Up_Time            0x0027   100   100   001    Pre-fail  Always       -       1875
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       2346
  5 Reallocated_Sector_Ct   0x0033   100   100   050    Pre-fail  Always       -       4
  7 Seek_Error_Rate         0x000a   100   100   000    Old_age   Always       -       0
  8 Seek_Time_Performance   0x0004   100   100   000    Old_age   Offline      -       0
  9 Power_On_Hours          0x0032   016   016   000    Old_age   Always       -       33708
 10 Spin_Retry_Count        0x0032   146   100   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       2253
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       93
193 Load_Cycle_Count        0x0032   001   001   000    Old_age   Always       -       1013638
194 Temperature_Celsius     0x0022   100   100   000    Old_age   Always       -       31 (Lifetime Min/Max 7/60)
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       4
197 Current_Pending_Sector  0x0032   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       13
220 Disk_Shift              0x0002   100   100   000    Old_age   Always       -       8256
222 Loaded_Hours            0x0032   033   033   000    Old_age   Always       -       26986
223 Load_Retry_Count        0x0032   100   100   000    Old_age   Always       -       0
224 Load_Friction           0x0022   100   100   000    Old_age   Always       -       0
226 Load-in_Time            0x0026   100   100   000    Old_age   Always       -       322
240 Head_Flying_Hours       0x0000   100   100   000    Old_age   Offline      -       0

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     33676         -
# 2  Extended offline    Aborted by host               90%     33675         -
# 3  Short offline       Aborted by host               90%     33675         -
# 4  Short offline       Completed without error       00%     33674         -
# 5  Short offline       Completed without error       00%     30183         -
# 6  Short offline       Completed without error       00%      9256         -
# 7  Short offline       Interrupted (host reset)      20%      7669         -
# 8  Short offline       Interrupted (host reset)      50%      4757         -
# 9  Short offline       Completed without error       00%       782         -
#10  Short offline       Completed without error       00%         0         -

Umzugskiste Festplatte 1

=== START OF INFORMATION SECTION ===
Model Family:     Maxtor DiamondMax D540X-4K family
Device Model:     MAXTOR 4K060H3
Serial Number:    673120525938
Firmware Version: A08.1500
User Capacity:    60,040,544,256 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   5
ATA Standard is:  ATA/ATAPI-5 T13 1321D revision 1
Local Time is:    Wed May  9 17:10:20 2012 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x0029   100   253   020    Pre-fail  Offline      -       0
  3 Spin_Up_Time            0x0027   077   077   020    Pre-fail  Always       -       2926
  4 Start_Stop_Count        0x0032   100   100   008    Old_age   Always       -       94
  5 Reallocated_Sector_Ct   0x0033   100   100   020    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000b   100   100   023    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0012   053   053   001    Old_age   Always       -       31052
 10 Spin_Retry_Count        0x0026   100   100   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0013   100   100   020    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   008    Old_age   Always       -       94
 13 Read_Soft_Error_Rate    0x000b   100   100   023    Pre-fail  Always       -       0
194 Temperature_Celsius     0x0022   093   083   042    Old_age   Always       -       18
195 Hardware_ECC_Recovered  0x001a   012   002   000    Old_age   Always       -       60675271
196 Reallocated_Event_Count 0x0010   100   253   020    Old_age   Offline      -       0
197 Current_Pending_Sector  0x0032   100   100   020    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x001a   182   182   000    Old_age   Always       -       18

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     31052         -
# 2  Short offline       Completed without error       00%     31052         -

Umzugskiste Festplatte 2 2008

=== START OF INFORMATION SECTION ===
Model Family:     SAMSUNG SpinPoint F1 RE series
Device Model:     SAMSUNG HE502IJ
Serial Number:    S1MTJ1EQ502794
Firmware Version: 1AA01112
User Capacity:    500,107,862,016 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   8
ATA Standard is:  ATA-8-ACS revision 3b
Local Time is:    Wed May  9 19:34:42 2012 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   100   100   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0007   086   086   011    Pre-fail  Always       -       4990
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       54
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   100   100   051    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0025   100   100   015    Pre-fail  Offline      -       0
  9 Power_On_Hours          0x0032   097   097   000    Old_age   Always       -       15783
 10 Spin_Retry_Count        0x0033   100   100   051    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x0012   100   100   000    Old_age   Always       -       5
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       54
 13 Read_Soft_Error_Rate    0x000e   100   100   000    Old_age   Always       -       0
183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
184 End-to-End_Error        0x0033   100   100   099    Pre-fail  Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   082   059   000    Old_age   Always       -       18 (Lifetime Min/Max 18/18)
194 Temperature_Celsius     0x0022   080   059   000    Old_age   Always       -       20 (Lifetime Min/Max 18/20)
195 Hardware_ECC_Recovered  0x001a   100   100   000    Old_age   Always       -       188
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   100   100   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x000a   100   100   000    Old_age   Always       -       0
201 Soft_Read_Error_Rate    0x000a   253   253   000    Old_age   Always       -       0

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%     15783         -
# 2  Extended offline    Completed without error       00%     15800         -

Mama

=== START OF INFORMATION SECTION ===
Model Family:     IBM Travelstar 48GH, 30GN, and 15GN
Device Model:     IC25N020ATDA04-0
Serial Number:    63L63MJ0883
Firmware Version: DA3OA76A
User Capacity:    20.003.880.960 bytes [20,0 GB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   5
ATA Standard is:  ATA/ATAPI-5 T13 1321D revision 3
Local Time is:    Sat May 12 14:12:40 2012 WS
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   100   100   062    Pre-fail  Always       -       0
  2 Throughput_Performance  0x0005   100   100   040    Pre-fail  Offline      -       0
  3 Spin_Up_Time            0x0007   131   131   033    Pre-fail  Always       -       1
  4 Start_Stop_Count        0x0012   099   099   000    Old_age   Always       -       2597
  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0005   100   100   040    Pre-fail  Offline      -       0
  9 Power_On_Hours          0x0012   066   066   000    Old_age   Always       -       15096
 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   099   099   000    Old_age   Always       -       2209
191 G-Sense_Error_Rate      0x000a   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       102
193 Load_Cycle_Count        0x0012   053   053   000    Old_age   Always       -       473281
194 Temperature_Celsius     0x0002   152   152   000    Old_age   Always       -       36 (0 50 255 255 0)
196 Reallocated_Event_Count 0x0032   098   098   000    Old_age   Always       -       372
197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       10

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%     15096         -
# 2  Extended offline    Completed without error       00%     15017         -

18.04.2012

Wahrscheinlichkeit, dass von X Leute zwei am selben Tag Geburstag haben…

Filed under: Allgemein — Tags: , — Thomas @ 11:04

Scheiß Wahrscheinlichkeitsrechung geht gegen jede Intuition.

Anz. Leute    WK für Gebtag am selben Tag
     25                     56%
     24                     53%
     23                     50%
     22                     47%
     21                     44%

Hier noch ein nettes Bildchen…

Wahrscheinlichkeit, dass von X Leute zwei am selben Tag Geburstag haben...

Wahrscheinlichkeit, dass von X Leute zwei am selben Tag Geburstag haben...

Und mein Programm:


template< typename T >
std::ostream& operator<< (std::ostream& o, vector< T > const& vec)
{
    for(size_t i = 0; i< vec.size(); i++)
        o << vec.at(i) << " ";
  return o;
}

// gebrustagstest
// 50WK dass 25? leute am gleichen tag geb. haben
int main() {

    int anzLeute = 61;

    vector  geburstage(anzLeute);
    int anzDoppelte = 0;
    int anzIterationen = 1e7;
    srand(time(0));

    cout << "Iterationen: "  << anzIterationen << "\n";

    for(int leute = 50; leute < anzLeute; leute++) {
        geburstage.resize(leute);
        anzDoppelte = 0;
//        cout << "WK fuer " << anzLeute << " Leute, dass sie am selben Tag Geburstag haben: ";
        for(int iterationen = 0; iterationen < anzIterationen; iterationen++) {
            // zufallsgeburstage holen
            for(int i = 0; i < leute; i++)
                geburstage[i] = rand() % 365 + 1;

            // sind doppelte vorhanden?
            sort(geburstage.begin(), geburstage.end());
            vector< int >::iterator it = adjacent_find (geburstage.begin(), geburstage.end());
            if (it!=geburstage.end()) {
              anzDoppelte++;
            }
        }
        cout << leute << " " << 100. * anzDoppelte / anzIterationen << "\n";
    }
    return 0;
}

12.04.2012

Neue Regale

Filed under: Allgemein — Tags: — Thomas @ 13:04

Endliche habe ich Zeit gefunden das Bücherregal zu montieren. Nun konnten auch die letzen Kisten ausgepackt werden.

Bücher

Bücher

Ablagefläche für Globus und Krimskrams

Ablagefläche für Kram

Ablagefläche für Kram

Und der abnehmbare Schreibtischanbau

Schreibtischanbau

Schreibtischanbau

09.04.2012

Faster Code – Part 6 – Sprungvorhersage again

Filed under: Allgemein — Tags: , , , — Thomas @ 16:04

Wie im letzten Post angekündigt, gibt es jetzt die genauere Analyse meines Tests.
Hier erstmal das Programm:

int mymin(int a, int b) __attribute__ ((noinline));
int mymin(int a, int b)
{
  asm ("");
  if (b < a)
    return b;
  return a;
}

int mymin2(int a, int b) __attribute__ ((noinline));
int mymin2(int a, int b)
{
  asm ("");
  return  b ^ ((a ^ b) & -(a < b)); // min(a, b)
}

int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
    long sum = 0;
    for(int i = 0; i < 1e7; i++) {
        a = rand();
        b = rand();
        c = std::min(a,b);
//        c = mymin1(a,b);
//        c = mymin2(a,b);
        sum+=c;
//        cout << a << " " << b << " " << c << "\n";
    }
    return 0;
}

Wie man sieht, gibt es zwei Funktion die jeweils die kleinere Zahl bestimmen. Einmal durch eine einfache if() Verzweigung und einmal durch eine Rechnung. Die beiden Funktionen sind mit den Attribute noinline [1] und einem inline Assembler Befehl versehen, damit der Compiler sie nicht weg optimiert. Sonst hat valgrind nichts zum messen ;)
Es gibt drei Durchläuft. Einmal mit std::min um die "normale Version" zu vermessen.
Dann meine min Version mit If. Und zum Schluss die Version mit Rechnung.
Compiliert wird immer mit

 g++ -O2  -g -Wall main.cpp

Bei Valgrind schalte ich die Cache Simulation ab, um die Ausführungszeit etwas zu verkürzen

valgrind --tool=cachegrind --branch-sim=yes --cache-sim=no ./a.out

Test 1
Mit std::min

==5210== I   refs:      1,821,485,345
==5210==
==5210== Branches:        230,216,253  (210,213,194 cond + 20,003,059 ind)
==5210== Mispredicts:         657,699  (    657,279 cond +        420 ind)
==5210== Mispred rate:            0.2% (        0.3%     +        0.0%   )

--------------------------------------------------------------------------------
         Ir          Bc     Bcm         Bi Bim  file:function
--------------------------------------------------------------------------------
880,000,000  80,000,000 645,163          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/random_r.c:random_r
    353,545      54,035   3,217          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/elf/dl-lookup.c:do_lookup_x
    176,933      28,792   2,876      2,144 252  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/elf/../sysdeps/i386/dl-machine.h:_dl_relocate_object
    138,235      31,695   1,684          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/string/strcmp.c:strcmp
    562,727      63,616   1,366          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/elf/dl-lookup.c:_dl_lookup_symbol_x

--------------------------------------------------------------------------------
-- Auto-annotated source: /home/kater/qtcode/plaintest/plaintest/main.cpp
--------------------------------------------------------------------------------
        Ir         Bc Bcm Bi Bim 

-- line 13 ----------------------------------------
         .          .   .  .   .
         .          .   .  .   .  int mymin2(const int& a, const int& b) __attribute__ ((noinline));
         .          .   .  .   .  int mymin2(const int& a, const int& b)
         .          .   .  .   .  {
         .          .   .  .   .    return  b ^ ((a ^ b) & -(a < b)); // min(a, b)
         .          .   .  .   .  }
         .          .   .  .   .
         .          .   .  .   .  int main()
         7          0   0  0   0  {
         .          .   .  .   .      int a = 0;
         .          .   .  .   .      int b = 0;
         .          .   .  .   .      int c = 0;
         .          .   .  .   .      long sum = 0;
80,000,000 10,000,000   5  0   0      for(int i = 0; i < 1e7; i++) {
10,000,000          0   0  0   0          a = rand();
10,000,000          0   0  0   0          b = rand();
         .          .   .  .   .          c = std::min(a,b);
         .          .   .  .   .          //c = mymin(a,b);
         .          .   .  .   .          sum+=c;
         .          .   .  .   .  //        cout << a << " " << b << " " << c << "\n";
         .          .   .  .   .      }
         .          .   .  .   .      return 0;
        11          0   0  0   0  }

Interessant sind hier nur Conditional branches executed (Bc) and conditional branches mispredicted (Bcm).
Wir haben also 657,699 falsch vorhergesagte Sprünge und 645,163 gehen für die Random Funktion drauf. Der Rest verteilt sich auf diverse Systemfunktionen. Aber es gibt keine falschen Sprünge für std::min. Der Compiler ist gut ;)
Fünf gehen für die For Schleife drauf. Hier erkennt die Sprungvorhersage schnell, dass es eine Schleife ist und nimmt immer den richtigen Weg.

Test 2
Mit mymin; if()

==10996== I   refs:      1,946,482,984
==10996==
==10996== Branches:        240,216,256  (220,213,197 cond + 20,003,059 ind)
==10996== Mispredicts:       5,658,603  (  5,658,183 cond +        420 ind)
==10996== Mispred rate:            2.3% (        2.5%     +        0.0%   )

--------------------------------------------------------------------------------
         Ir          Bc       Bcm         Bi Bim  file:function
--------------------------------------------------------------------------------
880,000,000  80,000,000   645,163          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/random_r.c:random_r
520,000,000 120,000,000        15          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/random.c:random
180,000,000           0         0          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/rand.c:rand
140,000,015  10,000,000         9          0   0  /home/kater/qtcode/plaintest/plaintest/main.cpp:main
120,001,144           0         0          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/string/../sysdeps/i386/i686/multiarch/strcspn.S:???
 84,997,627  10,000,000 5,000,895          0   0  /home/kater/qtcode/plaintest/plaintest/main.cpp:mymin(int, int)

--------------------------------------------------------------------------------
-- Auto-annotated source: /home/kater/qtcode/plaintest/plaintest/main.cpp
--------------------------------------------------------------------------------
        Ir         Bc       Bcm Bi Bim 

         .          .         .  .   .  #include 
         .          .         .  .   .  #include 
         .          .         .  .   .  using namespace std;
         .          .         .  .   .
         .          .         .  .   .
         .          .         .  .   .  int mymin(int a, int b) __attribute__ ((noinline));
         .          .         .  .   .  int mymin(int a, int b)
30,000,000          0         0  0   0  {
34,997,627 10,000,000 5,000,895  0   0    asm ("");
         .          .         .  .   .    if (b < a)
         .          .         .  .   .      return b;
         .          .         .  .   .    return a;
20,000,000          0         0  0   0  }
         .          .         .  .   .
         .          .         .  .   .  int mymin2(int a, int b) __attribute__ ((noinline));
         .          .         .  .   .  int mymin2(int a, int b)
         .          .         .  .   .  {
         .          .         .  .   .    asm ("");
         .          .         .  .   .    return  b ^ ((a ^ b) & -(a < b)); // min(a, b)
         .          .         .  .   .  }
         .          .         .  .   .
         .          .         .  .   .  int main()
         8          0         0  0   0  {
         .          .         .  .   .      int a = 0;
         .          .         .  .   .      int b = 0;
         .          .         .  .   .      int c = 0;
         .          .         .  .   .      long sum = 0;
80,000,000 10,000,000         9  0   0      for(int i = 0; i < 1e7; i++) {
20,000,000          0         0  0   0          a = rand();
10,000,000          0         0  0   0          b = rand();
         .          .         .  .   .  //        c = std::min(a,b);
30,000,000          0         0  0   0          c = mymin(a,b);
         .          .         .  .   .  //        c = mymin2(a,b);
         .          .         .  .   .          sum+=c;
         .          .         .  .   .  //        cout << a << " " << b << " " << c << "\n";
         .          .         .  .   .      }
         .          .         .  .   .      return 0;
        12          0         0  0   0  }

Jetzt sieht die Sache schon anders aus. Wir haben fünf Millionen falsch vorhergesagte Sprünge. Das macht 50%. Wie es zu erwarten war.

Test 3
Mit der Rechnung:

==11057== I   refs:      1,991,485,357
==11057==
==11057== Branches:        230,216,256  (210,213,197 cond + 20,003,059 ind)
==11057== Mispredicts:         657,699  (    657,279 cond +        420 ind)
==11057== Mispred rate:            0.2% (        0.3%     +        0.0%   )

--------------------------------------------------------------------------------
         Ir          Bc     Bcm         Bi Bim  file:function
--------------------------------------------------------------------------------
880,000,000  80,000,000 645,163          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/random_r.c:random_r
520,000,000 120,000,000      11          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/random.c:random
180,000,000           0       0          0   0  /build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/stdlib/rand.c:rand
140,000,015  10,000,000       5          0   0  /home/kater/qtcode/plaintest/plaintest/main.cpp:main
130,000,000           0       0          0   0  /home/kater/qtcode/plaintest/plaintest/main.cpp:mymin2(int, int)

--------------------------------------------------------------------------------
-- Auto-annotated source: /home/kater/qtcode/plaintest/plaintest/main.cpp
--------------------------------------------------------------------------------
        Ir         Bc Bcm Bi Bim 

-- line 9 ----------------------------------------
         .          .   .  .   .    asm ("");
         .          .   .  .   .    if (b < a)
         .          .   .  .   .      return b;
         .          .   .  .   .    return a;
         .          .   .  .   .  }
         .          .   .  .   .
         .          .   .  .   .  int mymin2(int a, int b) __attribute__ ((noinline));
         .          .   .  .   .  int mymin2(int a, int b)
40,000,000          0   0  0   0  {
70,000,000          0   0  0   0    asm ("");
         .          .   .  .   .    return  b ^ ((a ^ b) & -(a < b)); // min(a, b)
20,000,000          0   0  0   0  }
         .          .   .  .   .
         .          .   .  .   .  int main()
         8          0   0  0   0  {
         .          .   .  .   .      int a = 0;
         .          .   .  .   .      int b = 0;
         .          .   .  .   .      int c = 0;
         .          .   .  .   .      long sum = 0;
80,000,000 10,000,000   5  0   0      for(int i = 0; i < 1e7; i++) {
20,000,000          0   0  0   0          a = rand();
10,000,000          0   0  0   0          b = rand();
         .          .   .  .   .  //        c = std::min(a,b);
         .          .   .  .   .  //        c = mymin(a,b);
30,000,000          0   0  0   0          c = mymin2(a,b);
         .          .   .  .   .          sum+=c;
         .          .   .  .   .  //        cout << a << " " << b << " " << c << "\n";
         .          .   .  .   .      }
         .          .   .  .   .      return 0;
        12          0   0  0   0  }

Wie zu erwarten war gibt es keine fünf Millionen falsch vorhergesagten Sprünge. Wir sind so gut wie die Compiler Optimierung. Gebracht hats also nix ;)
Man bräuchte mal ein realen Anwendungsfall.
Ach ein Nachteil hat die Methode zur Berechnung der kleinsten Zahl: Man kann keine Reference auf die kleinste Zahl zurück geben. Kein Plan wie der Compiler das macht. It's magic.

[1] http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bnoinline_007d-function-attribute-2561

06.04.2012

Faster Code – Part 6 – Sprungvorhersage

Filed under: Allgemein — Tags: , , , — Thomas @ 19:04

Es ist ja so, dass ein Befehl auf der CPU nicht nur ausgeführt wird, er muss auch aus dem Speicher geladen und dekodiert werden. Heutige CPUs dekodieren schonmal den nächsten Befehl, wärend der aktuelle noch ausgeführt wird. Und der übernächste wird zeitgleich aus dem Speicher geholt. Das nennt man Prozessor-Pipeline [1] und das ist cool.

Uncool wird es allerdings, wenn der CPU Befehle vorbereitet hat, die dann doch garnicht ausgeführt werden. Das passiert zum Beispiel bei Sprüngen, wenn auf einmal der Code woanders weiter geht als die Pipeline es erwartet hat. Da gibt es auch wieder eine Menge Techniken um die Sprungvorhersage gut zu machen. Aber das will ich nicht weiter vertiefen.

Betrachten wir lieber folgendes Beispiel:


int min(int a, int b) {
  if (b < a)
    return b;
  return a;
}

Hier kann die Sprungvorhersage nichts tun. Was ist wahrscheinlicher, dass a kleiner ist als b oder doch nicht? Die Wahrscheinlichkeit liegt bei 50%. Wäre es nicht cool, wenn man die kleinere Zahl ausrechnen könnte? Dann braucht man keine Verzweigung im Programmpath und die Pipeline kann wunderschön arbeiten.

Man kann. Es gibt eine Seite mit lauter Bit Twiddling Hacks [2]. Und da gibt es noch viel mehr:

  • Compute the sign of an integer
  • Detect if two integers have opposite signs
  • Compute the integer absolute value (abs) without branching
  • Compute the minimum (min) or maximum (max) of two integers without branching
  • Determining if an integer is a power of 2
  • Um das Minimum zweier Interger Zahlen zu berechnen, kann man also folgende Formel verwenden:

    
    int x;  // we want to find the minimum of x and y
    int y;
    int r;  // the result goes here 
    
    r = y ^ ((x ^ y) & -(x < y)); // min(x, y)
    

    Um das ganze mal zu testen habe ich mir ein kleines Programm geschrieben, welches die kleinere von zwei Zufallszahlen bestimmt. Leider, oder zum Glück, wird die Funktion std::min() weg optimiert, so dass man keine Aussage mehr treffen kann, ob die Sprungvorhersage greift oder nicht. Also habe ich meine eigne min() Funktion geschrieben. Einmal mit einer if() und einmal mit der Rechnung.
    Valgrind [3] bringt ein branch-prediction Profiler mit. Die Bedienung ist einfach und das Ergebnis eindeutig. Da ich euch nicht langweilen will, hier gleich das Ergebnis:

  • Ja, wenn man Zufallszahlen benutzt, stimmt die Sprungvorhersage zu 50% nicht.
  • Ja, obrige Formel funktioniert und es gibt keine falsche Sprungvorhersage mehr
  • Nein, das Programm wurde nicht schneller. Der Test ist einfach zu simpel. Das berechnen der Zufallszahlen wird wohl der Flaschenhals sein.
  • Nein, obrige Formel bringt eigentlich nix. Der Compiler hat die std::min() wohl so gut optimiert, dass es keine Sprünge gab. Der erkennt das irgendwie und macht irgendwelche Tricks.
  • Die Details meines Tests werde ich das nächste Mal posten. Muss das erst etwas aufarbeiten.

    [1] http://de.wikipedia.org/wiki/Pipeline_%28Prozessor%29
    [2] http://www-graphics.stanford.edu/~seander/bithacks.html
    [3] http://valgrind.org/docs/manual/cg-manual.html

    04.04.2012

    Scheiß Fortran

    Filed under: Allgemein — Tags: — Thomas @ 10:04

    Ich hasse es, wirklich.
    Welche Ausgabe erwartet ihr bei diesem Programm?

    
    subroutine func()
      implicit none
      real :: time = 0;
      time = time + 1
      write(*,*) time
    end subroutine
    
    program test
      implicit none
      integer :: i
      do i = 1, 10
        call func()
      end do
    end
    

    Zehn mal die Ausgabe von “1″?
    Nein, falsch!

    thomas@cluster:~$ ./a.out
       1.000000
       2.000000
       3.000000
       4.000000
       5.000000
       6.000000
       7.000000
       8.000000
       9.000000
       10.00000
    

    Dann ist time also keine lokale Variable die bei jedem Aufruf von func() auf dem Stack gelegt wird? Und schon garnicht wird sie mit 0 initialisiert. Ist sie static und existiert die ganze Zeit über? Dann aber nicht auf dem Stack. Das nervt…

    // edit
    Die Variable wird statisch, sobald man sie bei der deklaration auch initialisiert.
    http://www.math.uni-leipzig.de/~hellmund/Vorlesung/scr4.pdf Seite 25 und 26

    Durch die Initialisierung wird die entsprechende Variable statisch! Die Initialisierung wird nur einmal, beim Programmstart, durchgeführt.

    Variablen sind statisch, wenn sie
    a) das save-Attribut tragen
    integer, save :: j
    b) bei der Definition initialisiert werden (s. oben) oder
    c) nach der Definition mit einer data-Anweisung initialisiert werden.

    30.03.2012

    Faster Code – Part 5 – huge pages

    Filed under: Allgemein — Tags: , , , — Thomas @ 21:03

    Tach und Willkommen beim fünften Teil von Faster Code. Heute geht es um huge page. Eine Page ist normal 4kb groß. Eine hugepage hat 2MB, 4MB oder nocht viel mehr. Hoch zu 1GB. Je nach System, CPU u.s.w.
    Die Größe ermittelt man so:

    $ grep Huge /proc/meminfo
    HugePages_Total:      46
    HugePages_Free:       46
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       4096 kB
    

    Wir haben also 4MB hugepage und es wurde 46 pages schon erstellt. Man kann sie so vom System anfordern:

    # echo 46 > /sys/kernel/mm/hugepages/hugepages-4096kB/nr_hugepages

    Es kann sein, dass man danach doch nicht 46 freie hugepages hat, da das System durch RAM Fragmentierung den angeforderten Speicher nicht am Stück liefern kann. Hier hilft es den Befehl mehrmals auszuführen oder neu zu starten.

    Und wozu brauch man das nun?
    Na um Translation Lookaside Buffer (TLB) misses zu verringern. Der TLB mappt eine virtuelle Adresse in eine physikalische Adresse um. Also so eine Art Cache der aber nur sehr sehr wenige Einträge halten kann (dafür ist er aber sehr schnell). Wenn man nun auf viele Adresse zugreift, die in Pages liegen die nah beinander liegen, dann läuft der TLB schnell zu und bereits vorhandenen Einträge werden überschrieben. Fehlende Einträge aus einem anderen Cache holen kostet Zeit und das wollen wir nicht.
    Wenn wir nun die Page größer machen, liegen mehr Variablen in einer Page und der TLB muss sich weniger merken. Einleuchtend, nicht wahr? ;)

    Und wie nutzt man huge pages?
    Es gibt verschiedene Methoden. Über das hugepagefs was ich aber umständlich finde, weil man von Hand ein Filesystem noch mountern muss. Dann gibt es seit Kernel 2.6.38 die Transparent Huge Pages (THP). Hier wird der ganze Aufwand im Hintergrund gehalten und man bekommt als User garnichts mehr mit. Man muss auch nicht sein Code änderen.
    Ob das System THP benutzt kann man kann man so erfahren

    $ cat /sys/kernel/mm/transparent_hugepage/enabled
    always madvise [never]
    

    In meinem Fall also nie. Wenn man sein Speicher normal über malloc/new anfordert, sollte man die Variable auf always stellen. Bei madvise muss noch irgendwo ein Flag übergeben werden. Hab vergessen wo.

    Die dritte Möglichkeit ist seinen Speicher per mmap() zu bestellen. Das find ich am besten. Man hat dann mehr Kontrolle was in hugepages landet und was nicht. Hier ein Beispiel:

    
      #include < sys/mman.h >
    
      /* Only ia64 requires this */
      #ifdef __ia64__
      #define ADDR (void *)(0x8000000000000000UL)
      #define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_FIXED)
      #else
      #define ADDR (void *)(0x0UL)
      #define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB)
      #endif
    
      // versuche speicher per mmap zu holen. wenn das fehlschlaegt nimm new oder valloc
      void *addr = mmap(ADDR, anzKnoten * sizeof(t_knoten_minimal), PROT_READ | PROT_WRITE, FLAGS, 0, 0);
      if (addr == MAP_FAILED) {
        perror("mmap");
        knoten_minimal = new t_knoten_minimal[anzKnoten];
      } else {
        knoten_minimal = new (addr) t_knoten_minimal[anzKnoten];
      }
    

    Und hats was gebracht?
    Jein, ehr nein. Ich hatte kein Testfall wo der TLB der Flaschenhals ist. Ich hab immer recht schnell neue Daten aus dem RAM geholt und wenig mit ihnen gerechnet. Die Leitung zum RAM ist natürlich sehr viel langsamer als der TLB seine neuen Adressen bekommt. Darum gab es so gut wie kein Speedup.
    Aber ich werde in meinem nächsten Code die Möglichkeit bereitstellen hugepages einfach zu nutzen.

    Older Posts »

    Powered by WordPress