Markus Rechberger / Linux Kernel
 
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

Veränderung (letzte Änderung) (keine anderen Diffs, Normalansicht)

Hinzugefügt: 950a951,955

==== Mutexes over Semaphores ====

recently many drivers got patched to use mutexes instead of semaphores, the reason behind that action - mutexes are supposed to be faster -
https://lwn.net/Articles/165039/

Linux Kernel

Kernel Threads

ps ax
  PID TTY      STAT   TIME COMMAND
    1 ?        S      0:00 init [2]       
    2 ?        SN     0:00 [ksoftirqd/0]
    3 ?        S<     0:00 [events/0]
    4 ?        S<     0:00 [khelper]
    5 ?        S<     0:00 [kblockd/0]
    6 ?        S      0:00 [khubd]
   32 ?        S      0:00 [pdflush]
   33 ?        S      0:00 [pdflush]
   35 ?        S<     0:00 [aio/0]
   34 ?        S      0:00 [kswapd0]
  619 ?        S      0:00 [kseriod]
  871 ?        S      0:00 [pccardd]
  873 ?        S      0:00 [pccardd]

Kernel Threads werden mit eckigen Klammern hervorgehoben um sie von normalen Prozessen zu unterscheiden

Kernel Prio

die priorität von prozessen wird mittels nice gesetzt [-20,19], im Linux Kernel werden Prioritäten einfacher von 0-139 dargestellt [-20,19] entspricht hierbei den prioritäten 100 - 139, der niedrigste Wert hat demnach auch die höchste Priorität

NUMA

http://lse.sourceforge.net/numa/faq/

Verteilung des Kernels im Speicher

cat /proc/iomem

Zeigt an das der Kernel erst ab dem 1. MB im Arbeitsspeicher beginnt der Code benötigt ungefähr 2.5 MB, der Datenabschnitt 0.9MB. Man sieht hier auch z.b die Adresse des BIOS ROM/RAMs, Video ROM/RAMs, usw.

Virtueller Adress Raum

Nettes Thema, wurde im Kernelbuch noch nicht beschrieben, jedoch ist dort oft davon die Rede.. Da ich's nicht verstanden hab hab ich's mir mal auf irc.oftc.net/#kernelnewbies erklären lassen :-))

02:47 <revenger1> noch wach?
02:51 <Bertl> yep yep ...
02:52 <revenger1> ich versteh absolut nicht was da noch sein sollte ausser swap und ram.. egal auch wenn das ganze virtuell ist musses doch mindestens existieren ansonsten könnte n teil von ner applikation im speicher fehlen..
02:53 <Bertl> nein, schau ...
02:53 <Bertl> z.b. du startest java
02:53 <Bertl> java sagt dem kernel ... ich will 1GB memory (weil es dann die mm verwaltung selber macht)
02:53 <Bertl> nun wäre das kernel ja dumm, wenn es 1GB ram belegen würde ...
02:54 <Bertl> also sagt es einfach, 1GB das sind ... hmmm ..262144 pages ...
02:54 <Bertl> da nimm und werd glücklich ...
02:55 <Bertl> alle pages sind read/write protected
02:55 <revenger1> ok und wenn eine page angesprochen wird die nicht mit dem ram/swap verbunden ist wird sie angelegt?
02:55 <Bertl> d.h. wenn java nun die erste (oder welche auch immer) page anfasst
02:56 <Bertl> dann wird die entsprechend angelegt ... zuerst im ram, dann möglicherweise ausgeswappt (später)
02:56 <Bertl> dann gibts aber auch noch pages die garnicht ins swap kommen
02:56 <revenger1> ok
02:56 <Bertl> z.b. alle files die gemapped werden (seis libraries oder executables)
02:56 <revenger1> is doch so einfach :)
02:57 <Bertl> und natürlich gibts auch pages die niemals gültig werden, wie der zero page blocker oder pages die sich mit dem kernel überschneiden würden ...
02:58 <revenger1> die erklärung war eindeutig danke!
02:58 <Bertl> gern geschehen, have fun!

http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/admin-guide/s1-memory-virt-details.html

http://www.xml.com/ldd/chapter/book/ch13.html

PAE Physical Address Extension

(intel invention) pae makes 4 extra bits available for addressing of memory, result => 2^36 => 64GiB though still there's the limitation of 4GiB for 32 bit applications so one process _cannot_ take more than 3GiB memory on a Linux system (since the kernel takes the other GiB? for managing the process)

{ZONE DMA}?First 16MiB of memory
{ZONE NORMAL}?16MiB - 896MiB
{ZONE HIGHMEM}?896 MiB? - End

OS (Arch ia32)relation 
Windows2:2 http://tinyurl.com/4gw7q
Solaris3.75:0.25 
Linux3:1; 3.5:0.5; 4:4 (there are patches available) 
FreeBSD2:2 (also adjustable) 

$ readelf --sections /usr/src/linux-2.6.9/vmlinux
There are 31 section headers, starting at offset 0x31528c:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        c0100000 001000 210c95 00  AX  0   0 16
  [ 2] __ex_table        PROGBITS        c0310ca0 211ca0 0010a8 00   A  0   0  4
  [ 3] .rodata           PROGBITS        c0311d60 212d60 044802 00   A  0   0 32
  [ 4] .pci_fixup        PROGBITS        c0356564 257564 000340 00  WA  0   0  4
  [ 5] __ksymtab         PROGBITS        c03568a4 2578a4 004828 00   A  0   0  4
  [ 6] __ksymtab_gpl     PROGBITS        c035b0cc 25c0cc 000240 00   A  0   0  4
  [ 7] __kcrctab         PROGBITS        c035b30c 25c30c 002414 00   A  0   0  4
  [ 8] __kcrctab_gpl     PROGBITS        c035d720 25e720 000120 00   A  0   0  4
  [ 9] __ksymtab_strings PROGBITS        c035d840 25e840 009bbb 00   A  0   0 32
  [10] __param           PROGBITS        c03673fc 2683fc 0003e8 00   A  0   0  4
  [11] .data             PROGBITS        c0368000 269000 082478 00  WA  0   0 4096
  [12] .data.page_aligne PROGBITS        c03eb000 2ec000 000800 00  WA  0   0 32
  [13] .data.cacheline_a PROGBITS        c03eb800 2ec800 0024c0 00  WA  0   0 32
  [14] .data.init_task   PROGBITS        c03ee000 2ef000 002000 00  WA  0   0 32
  [15] .init.text        PROGBITS        c03f0000 2f1000 015cca 00  AX  0   0 32
  [16] .init.data        PROGBITS        c0405ce0 306ce0 0040bc 00  WA  0   0 32
  [17] .init.setup       PROGBITS        c0409da0 30ada0 00036c 00  WA  0   0  4
  [18] .initcall.init    PROGBITS        c040a10c 30b10c 0001d8 00  WA  0   0  4
  [19] .con_initcall.ini PROGBITS        c040a2e4 30b2e4 000004 00  WA  0   0  4
  [20] .security_initcal PROGBITS        c040a2e8 310000 000000 00   W  0   0  1
  [21] .altinstructions  PROGBITS        c040a2e8 30b2e8 00236f 00   A  0   0  4
  [22] .altinstr_replace PROGBITS        c040c657 30d657 0008e1 00  AX  0   0  1
  [23] .exit.text        PROGBITS        c040cf40 30df40 000e60 00  AX  0   0 16
  [24] .init.ramfs       PROGBITS        c040e000 30f000 000085 00   A  0   0  1
  [25] .bss              NOBITS          c040f000 310000 023904 00  WA  0   0 32
  [26] .comment          PROGBITS        00000000 310000 005115 00      0   0  1
  [27] .note.GNU-stack   NOTE            00000000 315115 000000 00   X  0   0  1
  [28] .shstrtab         STRTAB          00000000 315115 000176 00      0   0  1
  [29] .symtab           SYMTAB          00000000 315764 07cb30 10     30 5da0  4
  [30] .strtab           STRTAB          00000000 392294 095ad2 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Linux Speicherverwaltung

 * Slab(Kachel) Allocator (1994, Jeff Bonwick, sun microsystems)
 * virtueller Speicher

Beside my mind (probably had a nice evening before)

03:41 < revenger> There are screens on:
03:41 < revenger>         82922.ttyp0.revenger    (Detached)
03:41 < revenger> that's not really possible with linux right?
03:41 < revenger> max pid is smallint 64767 or something like that
03:41 < revenger> or 62* ## (Added after the conversation) 65676 is it ors so don't really care about the accurat evalue
                  since I can look it up
03:42 < revenger> just wonder about that high pidnumber on my bsd box.. never 
                  recognized that before though
03:42 < shadows> I think it's possible.
03:42 < revenger> well possible without patches?
03:42 < shadows> and smallint is like 65535.
03:42 < revenger> yes.. but 82922
03:42 < revenger> it's a pid on bsd
03:43 < shadows> yeah... I dunno. I've seen up of 70k on my linux box all the 
                 time.
03:43 < revenger> never seen that before
03:43 < revenger> even our high load webservers just have <65k pids
03:44 < revenger> just started to start over with the pids here.. 30771 and 
                  afterwards 2277..
03:45 < shadows> I dunno.
03:45 < DrNick> /proc/sys/kernel/pid_max
03:45 -!- jayakumar2 [~jayakumar@219.95.45.130] has joined #kernelnewbies
03:45 < revenger>  cat /proc/sys/kernel/pid_max
03:45 < revenger> cat: /proc/sys/kernel/pid_max: No such file or directory
03:46 -!- sindian 
          [~sindian@va-charlottesville-cdnt1-bg8-11c-b-152.chvlva.adelphia.net] 
          has quit [Ping timeout: 480 seconds]
03:46 < revenger> not in the kernel here
03:46 < revenger> ok.. in 2.6 it's there
03:46 < revenger> 32768 thanks so far!
03:47 < DrNick> that's the default for compatibility with old apps that expect 
                pid_t to be a signed 16-bit integer
03:48 < revenger> 32768 is unsigned but why unsigned then?
03:48 < rene> then it would need to be 32767
03:48 < revenger> signed int was 65k even on my old 286pc
03:48 < revenger> unsigned*
03:48 < rene> 16-bit int = -32768 .. 32767
03:48 < revenger> signed was 32*
03:49 < revenger> -pids were allowed?!
03:49 < revenger> don't think so
03:49 < rene> nono
03:49 < rene> bu 32767 is therefore the maximum value you can represent in a 16bit int
03:50 < zinx> 16 bit signed int :/
03:50 < rene> int in the C sense is signed
03:50 < revenger> but why 32768 -?
03:50 < rene> otherwise it's an unsigned int ;)
03:50 < revenger> better but why -32768
03:51 < revenger> why would you need signed int for pids?
03:51 < zinx> revenger: because 1 bit is the sign, and 0 doesn't need a sign
03:51 < revenger> just say pid 0 is an error everything else is valid
03:51 < zinx> revenger: so you don't need 0x8000 and 0x0000 to both be 0
03:51 < zinx> revenger: therefore, 0x8000 is -32768
03:52 < zinx> revenger: (-1 is 0xffff, aka 0 - 1)
03:52 < revenger> but why for pids?.. still not clear either a process is valid 
                  or not .. lets say invalid is 0
03:52 < rene> revenger: you wouldn't need a negative PID, but (apparently) a 
              PID historically was just stored in a (signed) int, back in the 
              days when 32767 processes was insanity
03:53 < revenger> so back then it was a quickndirty startover :-)
03:53 < rene> now, having a max of 32767 would allow for compatibility with 
              programs that still expect that
03:53 < rene> (as to why it's 32768 and not 32767... bug, I guess)
03:53 < revenger> wonder what apps would require that limit .. opensource is 
                  known to be more flexible than closed source..
03:54 < revenger> anyway my question is answered thanks so far! :-) now the bsd 
                  question how many pids are allowed there.. (I'll better ask 
                  that question in a bsd channel as well)
03:56 < rene> btw: Documentation/sysctl/kernel.txt:PIDs of value pid_max or 
              larger are not allocated.
03:57 < rene> so just misnemd
03:57 < rene> *misnamed

Notizen

n elemente von from in den kernelspace kopieren:
copy_from_user(to, from, n);

API Changes Kernel 2.6.11:
remap_page_range() -> remap_pfn_range()

DMA Memory content/creative extigy 2 channels
-86 26 72 18 -95 21 36 14 -30 17 -116 11 -51 23 -108 18 109 22 96 18 -49 8 45 6 80 -2 24 -3 -89 -5 -118 -5 43 -2 -33 -2 -14 3 84 5 -116 2 91 4 35 -6 10 -4 -72 -9 -61 -7 14 -15 84 -13 -20 -16 7 -13 -33 -15 117 -13 105 -16 105 -15 72 -18 122 -18 123 -23 -84 -24 54 -26 -115 -28 -45 -28 -93 -30 -6 -31 89 -33 -80 -29 126 -32 19 -15 91 -19 86 2 27 -2 -7 10 -17 5 -70 8 -23 2 -114 11 113 5 -12 11 -74 5 14 11 -75 4 -39 15 -113 9 97 21 59 15 -106 23 106 17 58 25 -18 18 16 29 -23 22 -91 36 0 31 7 47 10 42 -99 58 -100 54 -80 66 61 64 43 63 73 62 -107 60 45 61 -77 57 0 60 35 47 81 51 76 32 90 38 80 21 86 29 94 17 -105 27 -108 15 3 28 85 10 -88 24 -19 7 -44 23 96 9 -106 26 -101 6 101 24 -85 6 91 24 82 4 -86 21 -29 -6 -93 11 114 -18 67 -2 31 -24 -28 -10 -107 -23 76 -9 43 -22 -99 -10 -38 -26 -77 -15 42 -25 95 -16 -46 -25 -95 -17 -1 -30 -94 -23 38 -21 47 -15 95 -10 -10 -4 0 -10 -10 -3 -107 -12 107 -2 119 -14 -81 -2 26 -19 11 -4 65 -28 -34 -11 -81 -34 -43 -14 24 -29 -56 -7 -86 -21 -47 4 -6 -21 43 7 -74 -20 114 9 71 -40 -15 -6 -16 -9 -18 111 -19 47 -20 42 -22 56 -16 22 -18 88 -8 59 -10 43 0 4 -2 55 6 -110 3 37 10 119 6 -9 10 19 6 -92 8 -46 2 80 6 20 0 -88 7 -64 1 -73 9 124 4 -73 9 -18 4 19 10 68 5 -85 7 22 2 -53 1 43 -5 81 -1 -79 -9 1 4 -118 -5 35 11 39 2 -6 14 -73 5 -110 15 10 6 47 16 94 6 -18 17 -53 7 -76 20 37 10 88 23 -125 12 -29 25 -81 14 18 28 121 16 19 27 39 15 71 24 -35 11 70 23 81 10 10 25 115 11 110 28 13 14 127 31 69 16 -18 31 -13 15 28 29 -116 12 -54 26 41 10 -88 27 107 11 38 29 -75 13 103 30 73 16 89 30 -49 17 74 26 -75 15 123 19 85 11 -40 13 110 8 -126 11 -25 8 -40 11 -72 11 125 13 10 15 60 15 -119 17 -76 14 -25 16 78 9 -77 10 -36 3 120 4 91 4 80 4 -85 5 1 5 46 6 -31 4 -93 6 101 4 -74 4 81 1 91 0 -56 -5 -29 -5 58 -10 87 -8 -53 -15 -6 -11 -83 -18 27 -9 -68 -18 -106 -7 -61 -17 -86 -9 7 -20 -21 -11 55 -24 8 -6 -80 -22 70 1 -68 -16 -25 6 -98 -11 15 9 81 -9 -85 8 94 -10 -66 6 -76 -13 77 4 118 -16 -95 3 -1 -18 41 7 -4 -15 110 14 41 -7 -106 21 100 0 69 22 95 1 20 19 116 -2 121 19 7 -1 112 23 65 3 -107 2 42 1 82 1 -20 3 19 4 -119 -5 -19 -5 94 -11 29 -10 120 -10 -58 -9 -22 -11 73 -8 -120 -16 -118 -12 36 -19 12 -13 118 -17 22 -9 -87 -16 118 -7 -3 -23 43 -13 -51 -31 95 -22 59 -28 73 -21 95 -18 -105 -13 100 -14 32 -10 92 -16 44 -13 -69 -16 59 -13 82 -16 38 -13 -22 -25 -116 -21 121 -35 13 -30 -21 -38 73 -32 7 -34 -29 -29 -101 -36 -120 -30 -29 -42 46 -36 127 -42 71 -38 24 -36 -59 -35 115 -38 -12 -39 -109 -44 41 -46 -52 -44 -33 -48 -58 -41 -11 -46 -92 -43 -114 -48 -5 -49 -6 -54 63 -50 86 -55 20 -46 20 -51 80 -43 -13 -49 124 -44 89 -50 -42 -44 -122 -51 36 -36 -108 -45 123 -32 3 -41 -73 -35 -99 -45 8 -31 91 -42 -55 -23 -102 -34 72 -16 -60 -28 -87 -16 8 -27 13 -19 -105 -31 126 -21 -104 -32 -62 -19 -61 -29 -68 -19 -108 -28 -94 -21 -89 -30 75 -17 -115 -27 52 -11 -5 -23 64 -10 71 -23 -32 -14 101 -28 103 -12 40 -27 68 -4 49 -19 72 3 0 -11 18 6 -63 -8 -79 6 63 -6 46 7 118 -5 -26 5 -76 -6 62 0 69 -11 -52 -3 -50 -14 -43 7 -60 -4 78 16 -6 4 112 18 111 6 -97 20 -71 7 -63 23 42 10 -97 26 -25 12 30 29 16 16 80 32 -48 2 -14 -9 -64 -9 -41 -6 -86 -8 -82 -3 118 -7 63 4 -17 -3 108 11 30 4 101 13 113 5 -113 12 -117 3 -72 10 111 0 14 7 -58 -5 -110 3 -36 -9 -9 1 -97 -10 10 -5 72 -16 -115 -16 73 -26 -32 -23 98 -32 -16 -30 -38 -38 -46 -35 -89 -41 -38 -36 19 -39 91 -37 28 -38 -63 -42 -90 -41 -128 -47 53 -44 40 -51 117 -47 110 -54 31 -48 34 -52 115 -45 -87 -48 -12 -39 77 -47 91 -36 21 -45 44 -32 83 -46 -44 -32 26 -50 86 -35 -67 -48 97 -32 -9 -40 2 -23 69 -30 8 -13 111 -23 -124 -6 -82 -20 -124 -3 -89 -21 69 -4 4 -24 95 -8 -26 -27 92 -11 -49 -22 -65 -7 38 -17 -40 -2 -93 -20 -89 -4 23 -19 45 -4 124 -19 126 -5 -37 -21 -5 -9 78 -20 -94 -11 -50 -16 1 -9 9 -10 94 -7 118 -9 -86 -8 30 -10 -89 -11 -26 -10 67 -12 70 -10 -104 -15 93 -17 96 -23 50 -17 -21 -25 7 -12 -66 -21 39 -12 -120 -22 -101 -12 112 -22 -67 -10 69 -20 30 -7 127 -19 97 -5 -36 -18 -6 -4 -31 -16 -118 -4 -104 -15 23 -7 51 -17 -95 -14 97 -23 121 -19 31 -28 94 -21 0 -30 61 -24 -64 -34 37 -24 -10 -35 94 -23 9 -33 -107 -24 -93 -34 53 -27 42 -37 126 -33 11 -43 -17 -37 -68 -47 72 0 9 12 107 -1 -37 11 85 -3 5 10 -53 -8 -58 5 -13 -7 -108 7 -117 -5 13 10 -9 -6 38 10 117 -5 -103 10 -116 -5 -74 9 73 -8 -50 4 -39 -9 -94 2 15 -6 -120 3 -38 -5 -114 4 -63 1 -35 9 27 4 68 11 28 7 -29 12 -50 10 30 15 127 12 -53 15 0 15 3 18 -44 18 42 22 -51 23 -96 27 98 29 91 33 -75 31 75 35 -20 29 -51 32 14 30 74 32 -60 27 -81 29 83 25 13 27 93 23 -125 24 -88 17 -119 17 -105 11 -97 9 48 6 61 2 -56 2 59 -3 -92 3 36 -3 -70 7 -38 0 -108 10 -102 3 74 10 60 3 41 7 19 0 -61 3 3 -3 -29 2 67 -3 25 3 66 -1 -24 5 -1 3 11 10 -81 9 5 12 -108 12 98 12 107 13 71 12 -44 13 -2 11 -121 14 -113 12 -100 16 -98 13 81 19 -121 9 90 16 51 1 33 8 -100 -6 -119 0 55 -12 -126 -8 112 -17 -1 -15 -63 -21 -87 -20 80 -23 -125 -24 -95 -24 -29 -27 34 -25 63 -30 -89 -29 -64 -36 -101 -32 75 -40 -63 -33 -5 -42 -113 -33 51 -41 58 -34 -91 -42 -69 -36 -89 -43 -89 -35 112 -42 -20 -36 63 -43 5 -36 16 -44 -89 -34 -9 -42 71 -30 106 -37 -51 -27 6 -32 -86 -22 -17 -27 -31 -17 16 -20 102 -14 -119 -17 -17 -14 80 -15 -65 -13 -73 -13 105 -12 0 -10 106 9 16 4 -70 10 113 8 -22 10 -65 11 -13 9 23 13 -66 5 22 10 36 2 -19 6 -99 0 -65 5 -56 0 -87 6 29 2 20 9 34 3 4 11 15 3 47 11 -2 5 -100 13 -86 9 -102 16 60 12 59 19 -33 10 3 19 -124 9 114 19 36 11 -88 22 -38 8 7 21 39 6 -50 17 30 5 72 15 112 3 -89 11 65 3 -96 9 110 8 118 13 -51 10 51 15 44 9 -101 13 118 5 114 10 56 1 2 7 -31 -1 -120 6 -71 -3 67 5 74 -1 -59 7 73 2 -80 11 -1 2 45 13 88 3 5 14 68 5 37 16 0 7 -9 17 64 9 -125 20 -98 10 -95 22 40 11 124 24 -71 12 -44 27 7 11 35 28 -77 6 -52 25 54 2 -9 22 108 0 27 22 95 -2 -20 19 49 -6 -124 14 103 -9 -40 9 -73 -9 101 8 106 -10 58 6 95 -12 -126 4 96 -10 -99 7 -70 -7 -32 11 -59 -8 -44 10 62 -10 53 7 52 -10 -81 5 -58 -10 2 5 -106 -8 19 6 -77 -4 -66 9 76 2 -71 14 68 8 -118 19 -67 13 95 23 -122 16 -124 24 -68 18 -76 25 -3 20 -33 27 -16 21 95 29 18 24 -65 31 -119 22 108 29 111 17 76 22 -57 12 -50 14 -120 7 -82 6 113 3 88 0 -32 5 117 1 43 12 50 7 32 11 3 6 53 7 37 2 -94 11 -27 6 -33 11 16 8 77 8 36 6 -57 11 -63 11 -119 17 -58 19 -50 17 35 22 54 13 95 19 76 9 3 -85 24 109 24 50 21 4 21 -94 19 -84 19 -109 15 17 16 -98 10 -56 11 48 8 0 10 48 5 77 7 2 0 -42 1 -45 -5 -68 -4 -110 -7 23 -7 71 -10 69 -12 69 -10 -25 -14 -123 -7 41 -11 -62 -8 -81 -13 -111 -8 -61 -14 53 -8 97 -15 84 -8 22 -16 71 -9 77 -19 -86 -11 -45 -23 -24 -11 69 -24 41 -10 -32 -26 81 -11 -120 -28 -9 -10 -50 -28 31 -9 -84 -29 115 -12 -31 -33 -108 -6 49 -27 -44 -2 11 -23 60 1 115 -21 80 3 -61 -19 -121 1 64 -20 -126 2 91 -19 100 7 38 -14 124 10 8 -11 120 10 -36 -12 49 12 -94 -10 118 15 63 -6 -122 14 -23 -7 14 11 38 -9 -82 16 94 -3 -71 22 -48 3 -107 22 -26 3 -103 22 18 4 21 21 -56 2 110 17 -117 -1 105 15 58 -2 3 15 -39 -2 -103 13 -57 -2 5 14 -35 0 -31 15 -83 4 40 13 42 4 -59 11 50 5 2 14 -24 9 99 15 -75 13 25 15 -68 15 106 15 64 18 -59 15 -65 20 -35 13 -13 20 -64 10 -18 19 -124 8 -75 19 -72 6 -71 19 117 6 -19 20 -42 6 77 22 -94 2 -106 18 -122 -1 -127 15 35 -1 -34 14 -104 0 -16 15 11 2 -8 16 -92 3 55 18 56 5 -106 19 39 4 -116 18 110 2 42 17 -64 4 33 20 -109 6 -58 22 82 4 72 21 59 6 -97 23 -115 7 -76 -106 -9 106 -2 -33 -9 -99 -1 27 1 27 10 -49 1 12 12 -42 -7 77 5 60 -6 48 7 4 1 -41 14 -64 0 -113 14 -117 -7 6 7 35 -9 -77 3 70 -6 -101 4 6 -5 125 3 -114 -9 -104 -1 -37 -12 -6 -5 92 -7 59 -1 -105 0 88 6 -30 5 81 11 27 10 -17 13 -25 12 114 15 0 14 96 16 -83 14 -39 16 -91 16 18 18 -32 20 105 22 97 26 38 29 87 25 -70 28 -73 20 -125 24 -54 23 -37 29 49 25 31 33 -60 24 112 33 -82 26 64 36 106 31 111 41 27 35 -43 44 -92 33 -19 42 114 30 81 39 -31 30 -4 38 99 29 -74 36 29 27 -79 33 -118 32 -17 37 84 24 -21 28 18 17 -16 21 -87 21 -37 26 -6 21 -112 27 -121 19 4 26 -47 18 -86 25 94 17 -66 23 -52 12 -17 18 -119 8 11 15 -38 7 105 14 -33 7 -127 14 -7 2 -128 10 -128 3 98 11 87 6 -56 12 94 2 99 7 -121 -2 -112 2 -21 -5 -97 -2 79 -6 -102 -5 74 -6 21 -6 66 -5 64 -7 7 -5 22 -9 27 -8 48 -14 -76 -13 -117 -21 -70 -14 -7 -24 -23 -14 110 -25 90 -12 93 -26 9 -9 43 -24 14 -8 98 -24 86 -5 59 -23 -54 -3 -64 -23 -52 -4 92 -24 -21 -4 98 -24 -43 1 39 -19 -3 7 5 -12 66 11 22 -8 113 10 -102 -9 -62 7 21 -10 -114 9 -42 -9 -28 13 34 -72 24 88 24 -46 25 110 24 75 30 39 28 126 32 0 30 -38 34 -73 32 7 43 -95 41 -41 53 48 53 48 61 64 61 113 64 70 65 78 66 33 68 53 65 -119 68 -89 56 -36 61 -60 43 -110 50 -88 33 -123 41 57 22 -43 30 116 11 -49 20 78 6 82 16 88 5 -63 15 -55 8 93 19 112 16 -1 26 -66 24 26 35 -32 29 -41 39 87 31 -13 40 20 30 -23 39 46 29 -105 39 15 28 29 38 -90 22 -73 31 -50 18 71 26 56 18 116 23 -122 17 20 21 -123 16 8 19 -16 17 37 19 33 22 97 21 121 25 122 22 -15 24 -59 19 114 21 127 14 -100 14 25 7 -55 3 27 -3 -103 -5 42 -10 -35 -10 -93 -14 -11 -14 -100 -17 25 -16 72 -19 -54 -18 -124 -20 -85 -18 58 -19 42 -18 -26 -19 -93 -20 -114 -19 -41 -22 -99 -20 -94 -24 18 -21 -20 -28 -9 -25 100 -31 -41 -28 -14 -35 6 -30 -7 -39 87 -33 4 -38 -65 -32 2 -33 31 -26 -97 -27 -94 -20 56 -19 58 -12 -45 -11 -15 -4 -15 -4 62 4 -63 0 5 8 55 3 -109 9 13 5 -16 9 93 3 15 7 -123 -2 -77 1 103 -7 -30 -4 -96 -9 76 -5 -117 -9 -119 -5 122 -10 126 -6 -101 -9 45 -5 72 -4 64 -1 18 1 125 3 -24 2 88 5 -50 2 59 6 43 3 83 7 77 5 17 9 39 8 63 11 -71 9 -111

C Format:
char foo[]={-86,26,72,18,-95,21,36,14,-30,17,-116,11,-51,23,-108,18,109,22,96,18,-49,8,45,6,80,-2,24,-3,-89,-5,-118,-5,43,-2,-33,-2,-14,3,84,5,-116,2,91,4,35,-6,10,-4,-72,-9,-61,-7,14,-15,84,-13,-20,-16,7,-13,-33,-15,117,-13,105,-16,105,-15,72,-18,122,-18,123,-23,-84,-24,54,-26,-115,-28,-45,-28,-93,-30,-6,-31,89,-33,-80,-29,126,-32,19,-15,91,-19,86,2,27,-2,-7,10,-17,5,-70,8,-23,2,-114,11,113,5,-12,11,-74,5,14,11,-75,4,-39,15,-113,9,97,21,59,15,-106,23,106,17,58,25,-18,18,16,29,-23,22,-91,36,0,31,7,47,10,42,-99,58,-100,54,-80,66,61,64,43,63,73,62,-107,60,45,61,-77,57,0,60,35,47,81,51,76,32,90,38,80,21,86,29,94,17,-105,27,-108,15,3,28,85,10,-88,24,-19,7,-44,23,96,9,-106,26,-101,6,101,24,-85,6,91,24,82,4,-86,21,-29,-6,-93,11,114,-18,67,-2,31,-24,-28,-10,-107,-23,76,-9,43,-22,-99,-10,-38,-26,-77,-15,42,-25,95,-16,-46,-25,-95,-17,-1,-30,-94,-23,38,-21,47,-15,95,-10,-10,-4,0,-10,-10,-3,-107,-12,107,-2,119,-14,-81,-2,26,-19,11,-4,65,-28,-34,-11,-81,-34,-43,-14,24,-29,-56,-7,-86,-21,-47,4,-6,-21,43,7,-74,-20,114,9,71,-40,-15,-6,-16,-9,-18,111,-19,47,-20,42,-22,56,-16,22,-18,88,-8,59,-10,43,0,4,-2,55,6,-110,3,37,10,119,6,-9,10,19,6,-92,8,-46,2,80,6,20,0,-88,7,-64,1,-73,9,124,4,-73,9,-18,4,19,10,68,5,-85,7,22,2,-53,1,43,-5,81,-1,-79,-9,1,4,-118,-5,35,11,39,2,-6,14,-73,5,-110,15,10,6,47,16,94,6,-18,17,-53,7,-76,20,37,10,88,23,-125,12,-29,25,-81,14,18,28,121,16,19,27,39,15,71,24,-35,11,70,23,81,10,10,25,115,11,110,28,13,14,127,31,69,16,-18,31,-13,15,28,29,-116,12,-54,26,41,10,-88,27,107,11,38,29,-75,13,103,30,73,16,89,30,-49,17,74,26,-75,15,123,19,85,11,-40,13,110,8,-126,11,-25,8,-40,11,-72,11,125,13,10,15,60,15,-119,17,-76,14,-25,16,78,9,-77,10,-36,3,120,4,91,4,80,4,-85,5,1,5,46,6,-31,4,-93,6,101,4,-74,4,81,1,91,0,-56,-5,-29,-5,58,-10,87,-8,-53,-15,-6,-11,-83,-18,27,-9,-68,-18,-106,-7,-61,-17,-86,-9,7,-20,-21,-11,55,-24,8,-6,-80,-22,70,1,-68,-16,-25,6,-98,-11,15,9,81,-9,-85,8,94,-10,-66,6,-76,-13,77,4,118,-16,-95,3,-1,-18,41,7,-4,-15,110,14,41,-7,-106,21,100,0,69,22,95,1,20,19,116,-2,121,19,7,-1,112,23,65,3,-107,2,42,1,82,1,-20,3,19,4,-119,-5,-19,-5,94,-11,29,-10,120,-10,-58,-9,-22,-11,73,-8,-120,-16,-118,-12,36,-19,12,-13,118,-17,22,-9,-87,-16,118,-7,-3,-23,43,-13,-51,-31,95,-22,59,-28,73,-21,95,-18,-105,-13,100,-14,32,-10,92,-16,44,-13,-69,-16,59,-13,82,-16,38,-13,-22,-25,-116,-21,121,-35,13,-30,-21,-38,73,-32,7,-34,-29,-29,-101,-36,-120,-30,-29,-42,46,-36,127,-42,71,-38,24,-36,-59,-35,115,-38,-12,-39,-109,-44,41,-46,-52,-44,-33,-48,-58,-41,-11,-46,-92,-43,-114,-48,-5,-49,-6,-54,63,-50,86,-55,20,-46,20,-51,80,-43,-13,-49,124,-44,89,-50,-42,-44,-122,-51,36,-36,-108,-45,123,-32,3,-41,-73,-35,-99,-45,8,-31,91,-42,-55,-23,-102,-34,72,-16,-60,-28,-87,-16,8,-27,13,-19,-105,-31,126,-21,-104,-32,-62,-19,-61,-29,-68,-19,-108,-28,-94,-21,-89,-30,75,-17,-115,-27,52,-11,-5,-23,64,-10,71,-23,-32,-14,101,-28,103,-12,40,-27,68,-4,49,-19,72,3,0,-11,18,6,-63,-8,-79,6,63,-6,46,7,118,-5,-26,5,-76,-6,62,0,69,-11,-52,-3,-50,-14,-43,7,-60,-4,78,16,-6,4,112,18,111,6,-97,20,-71,7,-63,23,42,10,-97,26,-25,12,30,29,16,16,80,32,-48,2,-14,-9,-64,-9,-41,-6,-86,-8,-82,-3,118,-7,63,4,-17,-3,108,11,30,4,101,13,113,5,-113,12,-117,3,-72,10,111,0,14,7,-58,-5,-110,3,-36,-9,-9,1,-97,-10,10,-5,72,-16,-115,-16,73,-26,-32,-23,98,-32,-16,-30,-38,-38,-46,-35,-89,-41,-38,-36,19,-39,91,-37,28,-38,-63,-42,-90,-41,-128,-47,53,-44,40,-51,117,-47,110,-54,31,-48,34,-52,115,-45,-87,-48,-12,-39,77,-47,91,-36,21,-45,44,-32,83,-46,-44,-32,26,-50,86,-35,-67,-48,97,-32,-9,-40,2,-23,69,-30,8,-13,111,-23,-124,-6,-82,-20,-124,-3,-89,-21,69,-4,4,-24,95,-8,-26,-27,92,-11,-49,-22,-65,-7,38,-17,-40,-2,-93,-20,-89,-4,23,-19,45,-4,124,-19,126,-5,-37,-21,-5,-9,78,-20,-94,-11,-50,-16,1,-9,9,-10,94,-7,118,-9,-86,-8,30,-10,-89,-11,-26,-10,67,-12,70,-10,-104,-15,93,-17,96,-23,50,-17,-21,-25,7,-12,-66,-21,39,-12,-120,-22,-101,-12,112,-22,-67,-10,69,-20,30,-7,127,-19,97,-5,-36,-18,-6,-4,-31,-16,-118,-4,-104,-15,23,-7,51,-17,-95,-14,97,-23,121,-19,31,-28,94,-21,0,-30,61,-24,-64,-34,37,-24,-10,-35,94,-23,9,-33,-107,-24,-93,-34,53,-27,42,-37,126,-33,11,-43,-17,-37,-68,-47,72,0,9,12,107,-1,-37,11,85,-3,5,10,-53,-8,-58,5,-13,-7,-108,7,-117,-5,13,10,-9,-6,38,10,117,-5,-103,10,-116,-5,-74,9,73,-8,-50,4,-39,-9,-94,2,15,-6,-120,3,-38,-5,-114,4,-63,1,-35,9,27,4,68,11,28,7,-29,12,-50,10,30,15,127,12,-53,15,0,15,3,18,-44,18,42,22,-51,23,-96,27,98,29,91,33,-75,31,75,35,-20,29,-51,32,14,30,74,32,-60,27,-81,29,83,25,13,27,93,23,-125,24,-88,17,-119,17,-105,11,-97,9,48,6,61,2,-56,2,59,-3,-92,3,36,-3,-70,7,-38,0,-108,10,-102,3,74,10,60,3,41,7,19,0,-61,3,3,-3,-29,2,67,-3,25,3,66,-1,-24,5,-1,3,11,10,-81,9,5,12,-108,12,98,12,107,13,71,12,-44,13,-2,11,-121,14,-113,12,-100,16,-98,13,81,19,-121,9,90,16,51,1,33,8,-100,-6,-119,0,55,-12,-126,-8,112,-17,-1,-15,-63,-21,-87,-20,80,-23,-125,-24,-95,-24,-29,-27,34,-25,63,-30,-89,-29,-64,-36,-101,-32,75,-40,-63,-33,-5,-42,-113,-33,51,-41,58,-34,-91,-42,-69,-36,-89,-43,-89,-35,112,-42,-20,-36,63,-43,5,-36,16,-44,-89,-34,-9,-42,71,-30,106,-37,-51,-27,6,-32,-86,-22,-17,-27,-31,-17,16,-20,102,-14,-119,-17,-17,-14,80,-15,-65,-13,-73,-13,105,-12,0,-10,106,9,16,4,-70,10,113,8,-22,10,-65,11,-13,9,23,13,-66,5,22,10,36,2,-19,6,-99,0,-65,5,-56,0,-87,6,29,2,20,9,34,3,4,11,15,3,47,11,-2,5,-100,13,-86,9,-102,16,60,12,59,19,-33,10,3,19,-124,9,114,19,36,11,-88,22,-38,8,7,21,39,6,-50,17,30,5,72,15,112,3,-89,11,65,3,-96,9,110,8,118,13,-51,10,51,15,44,9,-101,13,118,5,114,10,56,1,2,7,-31,-1,-120,6,-71,-3,67,5,74,-1,-59,7,73,2,-80,11,-1,2,45,13,88,3,5,14,68,5,37,16,0,7,-9,17,64,9,-125,20,-98,10,-95,22,40,11,124,24,-71,12,-44,27,7,11,35,28,-77,6,-52,25,54,2,-9,22,108,0,27,22,95,-2,-20,19,49,-6,-124,14,103,-9,-40,9,-73,-9,101,8,106,-10,58,6,95,-12,-126,4,96,-10,-99,7,-70,-7,-32,11,-59,-8,-44,10,62,-10,53,7,52,-10,-81,5,-58,-10,2,5,-106,-8,19,6,-77,-4,-66,9,76,2,-71,14,68,8,-118,19,-67,13,95,23,-122,16,-124,24,-68,18,-76,25,-3,20,-33,27,-16,21,95,29,18,24,-65,31,-119,22,108,29,111,17,76,22,-57,12,-50,14,-120,7,-82,6,113,3,88,0,-32,5,117,1,43,12,50,7,32,11,3,6,53,7,37,2,-94,11,-27,6,-33,11,16,8,77,8,36,6,-57,11,-63,11,-119,17,-58,19,-50,17,35,22,54,13,95,19,76,9,3,-85,24,109,24,50,21,4,21,-94,19,-84,19,-109,15,17,16,-98,10,-56,11,48,8,0,10,48,5,77,7,2,0,-42,1,-45,-5,-68,-4,-110,-7,23,-7,71,-10,69,-12,69,-10,-25,-14,-123,-7,41,-11,-62,-8,-81,-13,-111,-8,-61,-14,53,-8,97,-15,84,-8,22,-16,71,-9,77,-19,-86,-11,-45,-23,-24,-11,69,-24,41,-10,-32,-26,81,-11,-120,-28,-9,-10,-50,-28,31,-9,-84,-29,115,-12,-31,-33,-108,-6,49,-27,-44,-2,11,-23,60,1,115,-21,80,3,-61,-19,-121,1,64,-20,-126,2,91,-19,100,7,38,-14,124,10,8,-11,120,10,-36,-12,49,12,-94,-10,118,15,63,-6,-122,14,-23,-7,14,11,38,-9,-82,16,94,-3,-71,22,-48,3,-107,22,-26,3,-103,22,18,4,21,21,-56,2,110,17,-117,-1,105,15,58,-2,3,15,-39,-2,-103,13,-57,-2,5,14,-35,0,-31,15,-83,4,40,13,42,4,-59,11,50,5,2,14,-24,9,99,15,-75,13,25,15,-68,15,106,15,64,18,-59,15,-65,20,-35,13,-13,20,-64,10,-18,19,-124,8,-75,19,-72,6,-71,19,117,6,-19,20,-42,6,77,22,-94,2,-106,18,-122,-1,-127,15,35,-1,-34,14,-104,0,-16,15,11,2,-8,16,-92,3,55,18,56,5,-106,19,39,4,-116,18,110,2,42,17,-64,4,33,20,-109,6,-58,22,82,4,72,21,59,6,-97,23,-115,7,-76,-106,-9,106,-2,-33,-9,-99,-1,27,1,27,10,-49,1,12,12,-42,-7,77,5,60,-6,48,7,4,1,-41,14,-64,0,-113,14,-117,-7,6,7,35,-9,-77,3,70,-6,-101,4,6,-5,125,3,-114,-9,-104,-1,-37,-12,-6,-5,92,-7,59,-1,-105,0,88,6,-30,5,81,11,27,10,-17,13,-25,12,114,15,0,14,96,16,-83,14,-39,16,-91,16,18,18,-32,20,105,22,97,26,38,29,87,25,-70,28,-73,20,-125,24,-54,23,-37,29,49,25,31,33,-60,24,112,33,-82,26,64,36,106,31,111,41,27,35,-43,44,-92,33,-19,42,114,30,81,39,-31,30,-4,38,99,29,-74,36,29,27,-79,33,-118,32,-17,37,84,24,-21,28,18,17,-16,21,-87,21,-37,26,-6,21,-112,27,-121,19,4,26,-47,18,-86,25,94,17,-66,23,-52,12,-17,18,-119,8,11,15,-38,7,105,14,-33,7,-127,14,-7,2,-128,10,-128,3,98,11,87,6,-56,12,94,2,99,7,-121,-2,-112,2,-21,-5,-97,-2,79,-6,-102,-5,74,-6,21,-6,66,-5,64,-7,7,-5,22,-9,27,-8,48,-14,-76,-13,-117,-21,-70,-14,-7,-24,-23,-14,110,-25,90,-12,93,-26,9,-9,43,-24,14,-8,98,-24,86,-5,59,-23,-54,-3,-64,-23,-52,-4,92,-24,-21,-4,98,-24,-43,1,39,-19,-3,7,5,-12,66,11,22,-8,113,10,-102,-9,-62,7,21,-10,-114,9,-42,-9,-28,13,34,-72,24,88,24,-46,25,110,24,75,30,39,28,126,32,0,30,-38,34,-73,32,7,43,-95,41,-41,53,48,53,48,61,64,61,113,64,70,65,78,66,33,68,53,65,-119,68,-89,56,-36,61,-60,43,-110,50,-88,33,-123,41,57,22,-43,30,116,11,-49,20,78,6,82,16,88,5,-63,15,-55,8,93,19,112,16,-1,26,-66,24,26,35,-32,29,-41,39,87,31,-13,40,20,30,-23,39,46,29,-105,39,15,28,29,38,-90,22,-73,31,-50,18,71,26,56,18,116,23,-122,17,20,21,-123,16,8,19,-16,17,37,19,33,22,97,21,121,25,122,22,-15,24,-59,19,114,21,127,14,-100,14,25,7,-55,3,27,-3,-103,-5,42,-10,-35,-10,-93,-14,-11,-14,-100,-17,25,-16,72,-19,-54,-18,-124,-20,-85,-18,58,-19,42,-18,-26,-19,-93,-20,-114,-19,-41,-22,-99,-20,-94,-24,18,-21,-20,-28,-9,-25,100,-31,-41,-28,-14,-35,6,-30,-7,-39,87,-33,4,-38,-65,-32,2,-33,31,-26,-97,-27,-94,-20,56,-19,58,-12,-45,-11,-15,-4,-15,-4,62,4,-63,0,5,8,55,3,-109,9,13,5,-16,9,93,3,15,7,-123,-2,-77,1,103,-7,-30,-4,-96,-9,76,-5,-117,-9,-119,-5,122,-10,126,-6,-101,-9,45,-5,72,-4,64,-1,18,1,125,3,-24,2,88,5,-50,2,59,6,43,3,83,7,77,5,17,9,39,8,63,11,-71,9,-111}

Datei im Kernelmodus öffnen und beschreiben(dateirechte müssen beachtet werden!):
  mm_segment_t fs;
  fs = get_fs();
  set_fs (KERNEL_DS);//get_ds());
    
  pr_file = filp_open("/var/log/usb.log",O_RDWR|O_CREAT|O_APPEND,600);
  if (IS_ERR(pr_file)){
          printk("error unable to create /var/log/usb.log\n");
  } else {
          pr_file->f_op->write(pr_file, "foo", 3, &pr_file->f_pos);
          filp_close(pr_file,NULL);
  }

Linux DMA

http://www.linux-magazin.de/Service/Books/Buecher/HW-Treiber/memdma.html

Wenn alles zusammenkommt und auf einmal Sinn ergibt

Mit einer standard Debian kann man so ca 375 Threads erstellen. Woher kommt die Limitierung aber? Ziemlich einfach, der Kernel hat eine Aufteilung von 3:1 unter Linux (BSD und Windows sind häufig 2:2) das heißt von 4 GB physikalischen RAM können maximal 3 GB von einem Prozess verwendet werden. Teilt man jetzt 3 GB / die definierte Stack größe erhält man die Limitierung der Threads auf dem System. Die Größe der Stacksize wird in der limits.conf unter /etc/security festgelegt(das ganze muss auch mittels PAM erlaubt sein), sie kann jedoch auch "OnTheFly?" mittels ulimit -s geändert werden. Bei mysql ist zum Beispiel eine Größe von 128kbyte sinnvoll(laut Doku) was wiederum eine sehr hohe Anzahl von Verbindungen erlaubt.

Diskussion die mich dazu angeregt hat:
However, I was most amazed to see that the limit on stack size on
FreeBSD (5.3 Release) was 64M by default! I was just wondering, how is
FreeBSD able to create about a 1000 threads with that kind of a stack
limit. Also, is there anything specific in its implementation which
makes it difficult to incorporate in Linux? Wouldn't it be a good idea
to remove this "trade-off" between stack limit and number of threads
and fail thread creation only when we have run out of address space
being *actually used* in the stacks in a process.

Antwort
On FreeBSD the default thread stack size is not computed from ulimit -s,
but is constant.  They apparently only recently increased it to 1MB
(resp. 2MB on 64-bit arches), from 64K.

On Linux, the default thread stack size (except with fixed stack LinuxThreads)
is determined from ulimit -s (with a constant default if ulimit -s is
unlimited).

If your threaded application has specific needs for stack sizes, it can
always pthread_attr_setstacksize to whatever you find appropriate.

The thread library needs to know the stack size limit before creating
the thread, that can't be changed dynamically.

Quelle: linux-kernel@vger.kernel.org (mailinglist)

Linked Lists im Kernel

struct foobar{
    int a;
    int b;
    struct list_head list;
};

struct foobar testlist;
struct foobar *tmp;
struct list_head *pos, *q;
INIT_LIST_HEAD(&testlist.list);
tmp=(struct foobar*)malloc(sizeof(struct foobar));
tmp->a=1;
tmp->b=2;
list_add(&(tmp->list),&(testlist.list)); // fügt das element hinzu

list_for_each(pos, &testlist.list){
   tmp = list_entry(pos,struct foobar, list); // define
   printf("%d\n",tmp->a);
}

// alles in einem
list_for_each_entry(tmp,&foobar.list,list){
   printf("%d\n",tmp->a);
}

list_for_each_safe(pos,q,&foobar.list){
   tmp=list_entry(pos,struct foobar, list);
   list_del(pos);
   free(tmp);
}

Memory Mapped IO

http://www.kernelnewbies.org/documents/kdoc/deviceiobook/mmio.html

http://www.oreilly.de/german/freebooks/linuxdrive2ger/memmap.html

dev->frame[i].bufmem; (void*)

vmalloc_to_pfn
Map a vmalloc()-space virtual address to the physical page frame number.

remap_pfn_range

Kernelmodule

Aufbau:

Module verwenden das ELF Binärformat das mit einigen zusätzlichen Sektionen versehen ist.

__ksymtab und __ksymtab_gpl .. enthalten eine Symboltabelle mit allen Symbolen die vom Modul exportiert werden.

__kcrctab und __kcrctab_gpl enthalten Checksummen für alle GPL- exportierten Funktionen des Moduls.

in __versions befinden sich die checksummen für alle Referenzen die das modul aus externen Quellen verwendet. (diese sektionen werden nur angelegt wenn das versionskontroll feature bei der konfiguration des kerns aktiviert wurde.

__param speichert die informationen darüber, mit welchen Parametern ein Modul versorgt werden kann.

in .modinfo stehen die abhängigkeiten des jeweiligen moduls

Dummy modul

hello.c:
#include <linux/module.h
#include <linux/kernel.h>
#include <linux/fs.h>

static int dev_open(struct inode *inode, struct file *file){
        printk("device opened!\n");
        return(0);
}

static ssize_t dev_read(struct file *file, char __user * buffer, size_t length, loff_t *offset){
        printk("device opened!\n");
        return(0);
}

struct file_operations fops = {
                .read = dev_read,
                .open = dev_open,
};

static int __init hello_main(void)
{
        register_chrdev(185,"test",&fops);
        return 0;
}

static void __exit hello_exit(void)
{
        unregister_chrdev(185,"test");
}

module_init(hello_main);
module_exit(hello_exit);

test erscheint dann in /proc/devices

Makefile
obj-m += hello.o
#hello-objs = hello.o #additional objects here

KERNEL_VERSION = $(shell uname -r)
KERNEL_DIR = /lib/modules/$(KERNEL_VERSION)/build

default:
        $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules

Doku: <linuxkernel>Documentation/kbuild/makefiles.txt und modules.txt

Locking Mechanismen

 * Atomare Operationen

Während einer Operation wird ein lock Byte gesetzt (asm befehl) verhindert das der bus während es gesetzt ist von einem anderen prozess genutzt werden kann. Atomare Operationen sind in SMP Umgebungen sicher

 * Semaphore

Semaphoren wurden 1965 von E. W. Dijkstra erfunden. Führt ein Prozess eine down funktion aus wird der wert der semaphore auf 0 erniedrigt und der "kritische" code ausgeführt. sobald der kritische code beendet ist wird eine up funktion ausgeführt welche die semaphore wieder auf 1 erhöht.

will während der erste prozess sich im down segment befindet ein weiterer prozess den kritischen code betreten wird er vom kernel sozusagen schlafengelegt solange bis der erste prozess wieder die up funktion aufgerufen hat (welche den wert der semaphore wieder auf 1 erhöht und einen schlafenden prozess aus einer queue auswählt, welcher dann die down funktion weiter ausführt und die semaphore wieder auf 0 setzt)

 * und Spinlocks,

Spinlocks gibt es eigentlich nur auf NUMA Systemen, für Einprozessormaschinen gibt's dafür nen Wrapper.

01:37 < revenger> what are these flags for in for example spinlock_irqsave? the first one is clear the spinlock struct.. but the second one?
01:37 -!- santamarta [~Juanjo@195.Red-213-96-224.pooles.rima-tde.net] has quit [Remote host closed the connection]
01:38 < conman> save the state of the irqs and return it back after unlock ?
01:38 < revenger> well what's meant with state? what state?
01:39 < conman> enable/disabled irqs
01:39 < revenger> ah ok!
01:39 < revenger> thanks

debugging

die ersten 3 zeichen werden von syslog weggeschnitten sofern das kommentar eines von folgenden tags am anfang enthält:

 <0> System is not usable
 <1> kern alert
 <2> critical system
 <3> errors occured
 <4> warning
 <5> notice
 <6> information
 <7> debug info

pr_debug() ist ein wrapper um printk, welcher nur dann übersetzt wird sobald das kernelmodul mit -DDEBUG kompiliert wird

 {WARN ON}?(index==limit); -- gibt ein warning/zeilennummer und einen traceback aus an dieser stelle
 {BUG ON}?(foo==bar); -- das selbe wie {WARN ON}? nur der codeblock wird auch verlassen

auskommentieren von code im kernel
#if 0
...
...
#endif

license fun

MODULE_LICENSE("GPL\0for files in the \"GPL\" directory; for others, only LICENSE file applies");

no description .. just funny

modinfo

macros defined in the module
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Markus Rechberger");
MODULE_DESCRIPTION("just a module template");

modinfo test.ko
filename:       test.ko
license:        GPL
author:         Markus Rechberger
description:    just a module template
vermagic:       2.6.11.5 preempt PENTIUMM gcc-3.3

copy_to_user

der rückgabewert ist die anzahl bytes die nicht kopiert werden konnte

interrupt service routinen

es gibt davon nur 16 (siehe z.b xosview 0-15), Registrierung von Isrs kommt noch..

datenablage im speicher

Daten werden meist alligned in den speicher abgelegt

z.b
struct foobar {
__u8 a;
__u8 b;
__s32 c;
};

wenn der speicher bei 0xbffffa8c anfängt würde der block für __s32 c; bei addresse 0xbfffa8e beginnen, da diese adresse aber nicht durch 4 teilbar ist werden diese 2 bytes aus performancegründen "verschenkt". Will man die daten explizit gepackt angeben muss man am ende des structs noch __attribute__ packet; einfügen

TSC

02:27 < revenger> any idea what cpu_has_tsc stands for? (tsc actually)?
02:28 < bob2> it's a timer thing
02:28 < bob2> google says www.kernelhacking.org/docs/kernelhacking-HOWTO/indexs17.html
02:28 < revenger> right I got a book (kernel device drivers) but it doesn't explain what tsc is for..
02:28 < revenger> is/stands for
02:29 < revenger> time stamp counter ah
02:29 < revenger> thanks again

VMA

If a page needs to be aligned on a page boundary, {PAGE ALIGN}?() is used.

/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr)        (((addr) + PAGE_SIZE - 1) & PAGE_MASK)

>The PAGE_MASK macro is defined as
>
>/* PAGE_SHIFT determines the page size */
>#define PAGE_SHIFT 12
>#define PAGE_SIZE (1UL << PAGE_SHIFT)
>#define PAGE_MASK (~(PAGE_SIZE-1))
>
>in /linux/include/asm-i386/page.h
>
>and the macro usage is like
>
>pos=filp->f_pos;
>ppos=pos&PAGE_MASK

ppos will result something like the offset from the start of a page. It
will mean how much pos is disaligned by the 4k boundaries.

graphical overview: http://i30www.ira.uka.de/teaching/coursedocuments/106/03-06_Kernallokation-und-Mapping_Meinhardt.pdf

regarding linus, don't use vmalloc -> it's slow, everything's explained in that pdf so far..

11:31 < revenger_> hmm.. #define PAGE_ALIGN(addr)        (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
11:31 < revenger_> don't really understand that now..
11:53 < da-x> PAGE_ALIGN(addr) = returns the 'end' page address of an 'end' address.
11:53 < da-x> which is a quite cryptic description.
11:56 < da-x> suppose you have a buffer with an address X and size Y bytes. PAGE_ALIGN(X+Y) will return the first page which *doesn't* overlap with the buffer.
11:57 < da-x> which can be useful at times.
12:00 < da-x> a better description would be 'align to the next page if not already aligned'.

Einfach erklärt:

{PAGE ALIGN}? Beispiel:
  int b=55;
  b=PAGE_ALIGN(b);
b entspricht dann 4096 bytes
  int b=5555;
  b=PAGE_ALIGN(b);
b entspricht dann 8192 bytes


http://www.xtrj.org/ppc/ powerpc and linux inside..


hier nochmal linux device drivers online (already ordered that book as well)

http://www.xml.com/ldd/chapter/book/

Sequence Files/Proc filesystem

descrpition about sequence files on lwn.net (english) also includes a discussion

  https://lwn.net/Articles/22355/

another description of it in the german "Linux Treiber entwickeln" Book
  http://ezs.kr.hsnr.de/TreiberBuch/html/sec.proc01.html

Neues Geräte Modell (/sys/)

Das Gerätemodell bildet ab, wie die Prozessoren eines Systems mit seinen Controller-Bausteinen und diese wiederum mit den Peripheriekarten und mit sonstiger Hardware zusammenhängen. Eine detailierte Beschreibung gibts wiedermal in den Treiberbüchern..

z.b neue Bussysteme anlegen

static struct bus_type can = {
    .name = "CAN",
};

drvinit(){
  bus_register(&can);
}

drvexit(){
  bus_unregister(&can);
}

devfs

bereits in 2.6 als depreciated gekennzeichnet, da es angeblich race conditions enthält sowie z.b auch die zugriffsregelung nicht ordentlich implementiert ist (broken by design) ansonsten siehe devfs_mk_cdev, devfs_remove und devfs_mk_symlink

Module parametrieren

In Kernel 2.6 wurde das Makro {MODULE PARM}? durch drei neue Makros ersetzt: module_param, module_param_array und module_param_string.

Example (also includes a sysfs example):
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>

#define DRIVER_MAJOR 240

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Another sample module.");
MODULE_AUTHOR("Markus Rechberger");
static int exampleparam = 0;
//MODULE_PARM(exampleparam, "i");  or following line, the last argument is responsible for permissions
module_param(exampleparam,int,0);
MODULE_PARM_DESC(exampleparam, " sample desc, integer value(1-10)");

static struct file_operations fops;
static DECLARE_COMPLETION (dev_obj_is_free);
static int frequenz; // Zustandsvariable des Gerätes

static void mydevice_release( struct device *dev){
        complete(&dev_obj_is_free);
}

struct platform_device mydevice ={
        .name ="MyDevice",
        .id = 0,
        .dev = {
                .release = mydevice_release,
        }
};

static struct device_driver mydriver ={
        .name = "MyDevDrv",
        .bus = &platform_bus_type,
};

static ssize_t read_freq (struct device *dev, char *buf){
        snprintf(buf,256,"frequenz: %d",frequenz);
        return strlen(buf)+1;
}

static ssize_t write_freq (struct device *dev,const char *buf, size_t count){
        frequenz=simple_strtoul(buf, NULL, 0);
        return strlen(buf)+1;
}

static DEVICE_ATTR(freq, S_IRUGO|S_IWUGO, read_freq, write_freq);

static int __init drv_init(void){
        printk("example param: %d\n",exampleparam);
        if(register_chrdev(DRIVER_MAJOR,"MyDevice",&fops)==0){
                driver_register(&mydriver);
                platform_device_register(&mydevice);
                mydevice.dev.driver = &mydriver;
                device_bind_driver(&mydevice.dev);

                device_create_file(&mydevice.dev,&dev_attr_freq);
                return 0;
        }
        return -EIO;
}

static void __exit drv_exit(void){
        device_remove_file(&mydevice.dev,&dev_attr_freq);
        device_release_driver(&mydevice.dev);
        platform_device_unregister(&mydevice);
        driver_unregister(&mydriver);
        unregister_chrdev(DRIVER_MAJOR, "MyDevice");
        wait_for_completion(&dev_obj_is_free);
}

module_init(drv_init);
module_exit(drv_exit);

debian:/devel/kernel/example15# modinfo main.ko
filename:       main.ko
license:        GPL
description:    Another sample module.
author:         Markus Rechberger
vermagic:       2.6.11.5 preempt PENTIUMM gcc-3.3
depends:        
parm:           exampleparam: sample desc, integer value(1-10)

available datatypes:

typedesc
shortsigned short
ushortunsigned short
intsigned int
uintunsigned int
longsigned long
ulongunsigned long
charpstring
boolbool
invboolinverted bool

HZ

#ifdef __KERNEL__
# define HZ             1000            /* Internal kernel timer frequency */
# define USER_HZ        100             /* .. some user interfaces are in "ticks" */
# define CLOCKS_PER_SEC         (USER_HZ)       /* like times() */
#endif

# export
...
declare -x HOME="/root"
declare -x HUSHLOGIN="FALSE"
declare -x HZ="100"
...

so in the kernel HZ is set to 1000 which stands for 1 second, for applications it's set to 100

20:35 < rene> revenger_: the HZ environment variable isn't directly set by the 
              kernel. It's set from the ENV_HZ value in /etc/login/defs (if 
              present). Yes, it is supposed to be the kernel HZ and as such, 
              100 is stil correct, asthe kernel internal HZ and what is 
              presented to userspace are decoupled -- userspace is always 
              supposed to see 100
20:39 < rene> revenger_: (/etc/login.defs)

memory allocation

SetPageReserved?() wird benutzt um Speicher zu markieren der nicht ausgelagert werden soll

RingQueue?

here's an example of a ringqueue (usbvideo.c), the depreciated function wait_on is used in that driver as well, below the main functions which also get exported in the kernel.

#define RING_QUEUE_SIZE         (128*1024)      /* Must be a power of 2 */
#define RING_QUEUE_ADVANCE_INDEX(rq,ind,n) (rq)->ind = ((rq)->ind + (n)) & ((rq)->length-1)
#define RING_QUEUE_DEQUEUE_BYTES(rq,n) RING_QUEUE_ADVANCE_INDEX(rq,ri,n)
#define RING_QUEUE_PEEK(rq,ofs) ((rq)->queue[((ofs) + (rq)->ri) & ((rq)->length-1)])

struct RingQueue {
        unsigned char *queue;   /* Data from the Isoc data pump */
        int length;             /* How many bytes allocated for the queue */
        int wi;                 /* That's where we write */
        int ri;                 /* Read from here until you hit write index */
        wait_queue_head_t wqh;  /* Processes waiting */
};

static void RingQueue_Initialize(struct RingQueue *rq)
{
        assert(rq != NULL);
        init_waitqueue_head(&rq->wqh);
}

static void *usbvideo_rvmalloc(unsigned long size)
{
        void *mem;
        unsigned long adr;

        size = PAGE_ALIGN(size); // padding up to a full page size (for example if size is 234 size will get padded up to 4096
        mem = vmalloc_32(size);
        if (!mem)
                return NULL;

        memset(mem, 0, size); /* Clear the ram out, no junk to the user -- also security issue, passwords might be in that memoryjunk worst case */
        adr = (unsigned long) mem;
        while (size > 0) {
                SetPageReserved(vmalloc_to_page((void *)adr)); // pin them in memory (no swapping out for these addresses)
                adr += PAGE_SIZE;
                size -= PAGE_SIZE;
        }

        return mem;
}


static void RingQueue_Allocate(struct RingQueue *rq, int rqLen)
{
        /* Make sure the requested size is a power of 2 and
           round up if necessary. This allows index wrapping
           using masks rather than modulo */

        int i = 1;
        assert(rq != NULL);
        assert(rqLen > 0);

        while(rqLen >> i)
                i++;
        if(rqLen != 1 << (i-1))
                rqLen = 1 << i;

        rq->length = rqLen;
        rq->ri = rq->wi = 0; // read index = write index = 0
        rq->queue = usbvideo_rvmalloc(rq->length); 
        assert(rq->queue != NULL);
}

int RingQueue_Enqueue(struct RingQueue *rq, const unsigned char *cdata, int n)
{
        int enqueued = 0;

        assert(rq != NULL);
        assert(cdata != NULL);
        assert(rq->length > 0);
        while (n > 0) {
                int m, q_avail;

                /* Calculate the largest chunk that fits the tail of the ring */
                q_avail = rq->length - rq->wi;
                if (q_avail <= 0) {
                        rq->wi = 0;
                        q_avail = rq->length;
                }
                m = n;
                assert(q_avail > 0);
                if (m > q_avail)
                        m = q_avail;

                memcpy(rq->queue + rq->wi, cdata, m);
                RING_QUEUE_ADVANCE_INDEX(rq, wi, m);
                cdata += m;
                enqueued += m;
                n -= m;
        }
        return enqueued;
}

int RingQueue_Dequeue(struct RingQueue *rq, unsigned char *dst, int len)
{
        int rql, toread;

        assert(rq != NULL);
        assert(dst != NULL);

        rql = RingQueue_GetLength(rq);
        if(!rql)
                return 0;

        /* Clip requested length to available data */
        if(len > rql)
                len = rql;

        toread = len;
        if(rq->ri > rq->wi) {
                /* Read data from tail */
                int read = (toread < (rq->length - rq->ri)) ? toread : rq->length - rq->ri;
                memcpy(dst, rq->queue + rq->ri, read);
                toread -= read;
                dst += read;
                rq->ri = (rq->ri + read) & (rq->length-1);
        }
        if(toread) {
                /* Read data from head */
                memcpy(dst, rq->queue + rq->ri, toread);
                rq->ri = (rq->ri + toread) & (rq->length-1);
        }
        return len;
}

static void RingQueue_InterruptibleSleepOn(struct RingQueue *rq)
{
        assert(rq != NULL);
        interruptible_sleep_on(&rq->wqh);
}

void RingQueue_WakeUpInterruptible(struct RingQueue *rq)
{
        assert(rq != NULL);
        if (waitqueue_active(&rq->wqh))
                wake_up_interruptible(&rq->wqh);
}

void RingQueue_Flush(struct RingQueue *rq)
{
        assert(rq != NULL);
        rq->ri = 0;
        rq->wi = 0;
}

RingQueue? Test im Userspace:
Values: 134515731 - 6 - 0
enqueued: 6 Markus
Values: 134515731 - 6 - 0
enqueued: 6 Markus
Values: 134515731 - 6 - 0
enqueued: 6 Markus
Values: 134515731 - 6 - 0
enqueued: 6 Markus
Queue: Mark //queuecontent 4 chars
Values: 134515768 - 11 - 0 Rechberger
Queue: usMarkusMarkusMarkusRechberger //queuecontent the rest

Linux DMA

http://www.linuxjournal.com/article/1222

also isa ist limitiert auf die ersten 16 MB Ram für DMA transfers

IO

the first parallel port starts at 0x378, the second one is 0x278 there are 12 output pins and 5 input pins (rest is grounding)

Mutexes over Semaphores

recently many drivers got patched to use mutexes instead of semaphores, the reason behind that action - mutexes are supposed to be faster - https://lwn.net/Articles/165039/


StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 17. Januar 2006 3:16 (diff))
Suchbegriff: gesucht wird
im Titel
im Text