DOMANDA Come ambientarsi nella repository del kernel Linux?

Pubblicità

Hero467

Utente Attivo
Messaggi
695
Reazioni
406
Punteggio
75
Salve a tutti, ho recentemente iniziato a visitare la repository su github del kernel Linux, ma mi sono reso conto che non riesco a “muovermi” tra le sezioni, poiché non capisco cosa fa una determinata sezione, e i vari file presenti non mi dicono nulla.
Qualcuno può gentilmente farmi una velocissima introduzione a come funziona? Così capisco come muovermi e imparare il significato dei programmi lì presenti
 
Qui la documentazione del kernel
Da quello che ricordo di C non sapevi niente e stavi iniziando a dare una sbirciata
Btw, qui anche la guida introduttiva allo sviluppo del kernel
Infine nel git ufficiale c'è il readme che cito qui sotto
Codice:
Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.
 
Grazie mille. Esatto, di C so poco niente. Proprio per questo mi era stato consigliato da Andretti di dargli un'occhiata, essendo che è scritto in modo molto pulito
 
Ah quindi semplicemente vuoi leggere il kernel e le loro componenti.
Oddio, il progetto del kernel, imho, è un bel fardello da mettersi lì a leggere.
Comunque la struttura dovrebbe essere così
arch
The arch subdirectory contains all of the architecture specific kernel code. It has further subdirectories, one per supported architecture, for example i386 and alpha.

include
The include subdirectory contains most of the include files needed to build the kernel code. It too has further subdirectories including one for every architecture supported. The /include/asm subdirectory is a soft link to the real include directory needed for this architecture, for example /include/asm-i386. To change architectures you need to edit the kernel makefile and rerun the Linux kernel configuration program.

init
This directory contains the initialization code for the kernel and it is a very good place to start looking at how the kernel works.

mm
This directory contains all of the memory management code. The architecture specific memory management code lives down in /arch/*/mm/, for example /arch/i386/mm/fault.c.

drivers
All of the system's device drivers live in this directory. They are further sub-divided into classes of device driver, for example block.

ipc
This directory contains the kernels inter-process communications code.

modules
This is simply a directory used to hold built modules.

fs
All of the file system code. This is further sub-divided into directories, one per supported file system, for example vfat and ext2.

kernel
The main kernel code. Again, the architecture specific kernel code is in /arch/*/kernel.

net
The kernel's networking code.

lib
This directory contains the kernel's library code. The architecture specific library code can be found in /arch/*/lib/.

scripts
This directory contains the scripts (for example awk and tk scripts) that are used when the kernel is configured.


Più che leggere il kernel, che è scritto davvero bene e ben documentato e con un suo standard ( considera che ci lavorano mille mila persone e pensa se ognuno scrivesse il codice con il proprio standard ) non sarebbe meglio studiarsi un libro e poi creare pian piano programmini?
Questo ad esempio è un eserciziario dell'università di ing. informatica di Pavia


Questa è una porzione di codice del kernel della componente timer

C:
/**
 * set_normalized_timespec - set timespec sec and nsec parts and normalize
 *
 * @ts:        pointer to timespec variable to be set
 * @sec:    seconds to set
 * @nsec:    nanoseconds to set
 *
 * Set seconds and nanoseconds field of a timespec variable and
 * normalize to the timespec storage format
 *
 * Note: The tv_nsec part is always in the range of
 *    0 <= tv_nsec < NSEC_PER_SEC
 * For negative values only the tv_sec field is negative !
 */
void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 nsec)
{
    while (nsec >= NSEC_PER_SEC) {
        /*
         * The following asm() prevents the compiler from
         * optimising this loop into a modulo operation. See
         * also __iter_div_u64_rem() in include/linux/time.h
         */
        asm("" : "+rm"(nsec));
        nsec -= NSEC_PER_SEC;
        ++sec;
    }
    while (nsec < 0) {
        asm("" : "+rm"(nsec));
        nsec += NSEC_PER_SEC;
        --sec;
    }
    ts->tv_sec = sec;
    ts->tv_nsec = nsec;
}
EXPORT_SYMBOL(set_normalized_timespec64);
 
Imho a legger il source del kernel, essendo che sei alle prime armi, non impari na cippa, anzi, vai in confusione e basta.
Io ed un mio amico ai tempi che facevamo c ci siamo costruiti un gioco dell'oca multiplayer ( sullo stesso terminale ), tanti programmini che magari di per sè non servivano a niente, ma servivano per applicare quello che si imparava.
Naturalmente l'approccio con un libro è comodo perchè va a "salire" e tutti gli esercizi van a pari passo con quello che hai appena letto ed implementando pure quello precedente.
Esempio:
cap 1 scanf
esercizi scanf
cap 2 array
esercizi array + esercizi array con scanf
cap 3 struct
esercizi struct + esercizi array con scanf e con struct

Andare a metter mano a programmi complessi non ha alcun senso ( è un po' come se sai a malapena fare le addizioni e vuoi imparare le moltiplicazioni )
 
Pubblicità
Pubblicità
Indietro
Top