[PATCH] Add getcpu

Florian Weimer fweimer@redhat.com
Wed Dec 5 21:55:00 GMT 2018


* H. J. Lu:

> +@node Process Information
> +@section Process Information

I'm not sure if this is the right place.  This is specifically not a
process attribute, after all.  Perhaps it will fit better into the
discussion of scheduling-related functionality?

> +@deftypefun int getcpu (unsigned int *cpu, unsigned int *node)
> +@standards{Linux, <sched.h>}
> +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}

Can we unwind through vsyscalls?  If not, the function is not AC-safe.

> +The @code{getcpu} function identifies the processor and node on which
> +the calling thread or process is currently running and writes them into
> +the integers pointed to by the @var{cpu} and @var{node} arguments.  The
> +processor is a unique small integer identifying a CPU.  The node is a

“small nonnegative integer”

> +unique small identifier identifying a NUMA node.  When either @var{cpu}

“small nonnegative integer” (not “identifier”)

> +or @var{node} is @code{NULL}, nothing is written to the respective
> +pointer.

Should we add a caveat that due to CPU hotplugging, the values might not
be so small after a while?

> +The return value is @code{0} on success and @code{-1} on failure.  The
> +following @code{errno} error condition is defined for this function:
> +
> +@table @code
> +@item EFAULT
> +Arguments point outside the calling process's address space.
> +@end table
> +@end deftypefun

I don't think the vsyscall can detect the EFAULT error condition
reliably.  Should we really document it?

What about ENOSYS?  Is this system call really supported on all
architectures?

Thanks,
Florian



More information about the Libc-alpha mailing list