Re: How to write a kernel patch to expose a kernel-level function?



hzmonte@xxxxxxxxxxx wrote:
http://altlinux.org/index.php?module=sisyphus&package=cpuid

Thx but no, it is not what I want. This package displays the CPU spec like who the manufacturer is and what model it is, etc. What I want, and what smp_processor_id() returns, is which logical processor the calling thread is running on. Is CPU0, CPU1, or CPU2, for example?

In both cases you need a piece of kernel code, a patch or a kernel module

So my question is How to write a kernel patch? Is it as simple as adding a statement in the source like "EXPORT TO USER-SPACE smp_processor_id"? Any pointer to how to do it? Ay more concrete guideline?


The kernel runs in a private address space compared to
the user code. You cannot use the kernel internal
address for anything in user code, and it's not allowed
to even look at the contents of the address.

For details, get the books

  Understanding the Linux Kernel

and

  Linux Device Drivers

and read and understand them before attempting own
kernel coding.

Both books are published by O'Reilly.

IMHO, creating a /proc file is the easiest way of
reading the identifier.

A different story is that the result is probably
invalid at the time your user code gets it. There
is no guarantee that the process is running on
the reported processor anymore.

--

Tauno Voipio
tauno voipio (at) iki fi

.



Relevant Pages

  • Re: LILO booting problems
    ... Tauno Voipio wrote: ... The error arises from the kernel which does not know the ... have not loaded the associated ramdisk file from the USB ... loaded in the root partition of the USB HD partition in question. ...
    (comp.os.linux.misc)
  • Re: RFC: THE OFFLINE SCHEDULER
    ... out portions of the cached data. ... But that means the user code that is running on the ... CPU must not do anything that wakes the kernel. ... So we don't need to offload stats to other CPUs, ...
    (Linux-Kernel)
  • Re: [patch] inotify: make user visible types portable
    ... Are you saying to use __u32 so user code can compile with these kernel ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: TRAP 0000 in OS2KRNL
    ... important than typical user code. ... Why is it more important for the kernel to crash? ... There ARE reasons to have cell phone cameras... ...
    (comp.os.os2.bugs)
  • Re: [PATCH 01/13] [RFC] ipath basic headers
    ... > + * to communicate between kernel and user code. ... Do we really need this ugly userspace emulation code in the kernel? ... [snip, snip] ... Please use static inlines instead for readability. ...
    (Linux-Kernel)