Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


tracefs_instance_set_affinity(3) — Linux manual page

NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |EXAMPLE |FILES |SEE ALSO |AUTHOR |REPORTING BUGS |LICENSE |RESOURCES |COPYING |NOTES |COLOPHON

LIBTRACEFS(3)               libtracefs ManualLIBTRACEFS(3)

NAME        top

       tracefs_instance_set_affinity, tracefs_instance_set_affinity_set,       tracefs_instance_set_affinity_raw, tracefs_instance_get_affinity,       tracefs_instance_get_affinity_set,       tracefs_instance_get_affinity_raw - Sets or retrieves the affinity       for an instance or top level for what CPUs enable tracing.

SYNOPSIS        top

#include <tracefs.h>       inttracefs_instance_set_affinity(struct tracefs_instance *instance, const char *cpu_str);       inttracefs_instance_set_affinity_set(struct tracefs_instance *instance, cpu_set_t *set, size_tset_size);       inttracefs_instance_set_affinity_raw(struct tracefs_instance *instance, const char *mask);       char *tracefs_instance_get_affinity(struct tracefs_instance *instance);       inttracefs_instance_get_affinity_set(struct tracefs_instance *instance, cpu_set_t *set, size_tset_size);       char *tracefs_instance_get_affinity_raw(struct tracefs_instance *instance);

DESCRIPTION        top

       These functions set or retrieve the CPU affinity that limits what       CPUs will have tracing enabled for a given instance defined by theinstance parameter. Ifinstance is NULL, then the top level       instance is affected.       Thetracefs_instance_set_affinity()function takes a stringcpu_str that is a list of CPUs to set the affinity for. Ifcpu_str       is NULL, then all the CPUs in the system will be set. The format       ofcpu_str is a comma delimited string of decimal numbers with no       spaces. A range may be specified by a hyphen.       For example: "1,4,6-8"       The numbers do not need to be in order except for ranges, where       the second number must be equal to or greater than the first.       Thetracefs_instance_set_affinity_set()function takes a CPU set       defined byCPU_SET(3). The size of the set defined byset_size is       the size in bytes ofset. Ifset is NULL then all the CPUs on the       system will be set, andset_size is ignored.       Thetracefs_instance_set_affinity_raw()function takes a string       that holds a hexidecimal bitmask, where each 32 bits is separated       by a comma. For a machine with more that 32 CPUs, to set CPUS 1-10       and CPU 40:           "100,000007fe"       Where the above is a hex representation of bits 1-10 and bit 40       being set.       Thetracefs_instance_get_affinity()will retrieve the affinity in       a human readable form.       For example: "1,4,6-8"       The string returned must be freed withfree(3).       Thetracefs_instance_get_affinity_set()will set all the bits in       the passed in cpu set (fromCPU_SET(3)). Note it will not clear       any bits that are already set in the set but the CPUs are not. If       only the bits for the CPUs that are enabled should be set, a       CPU_ZERO_S() should be performed on the set before calling this       function.       Thetracefs_instance_get_affinity_raw()will simply read the       instance tracing_cpumask and return that string. The returned       string must be freed withfree(3).

RETURN VALUE        top

       All the set functions return 0 on success and -1 on error.       The functionstracefs_instance_get_affinity()andtracefs_instance_get_affinity_raw()returns an allocated string       that must be freed withfree(3), or NULL on error.       The functiontracefs_instance_get_affinity_set()returns the       number of CPUs that were found set, or -1 on error.

ERRORS        top

       The following errors are for all the above calls:EFBIGif a CPU is set that is greater than what is in the system.EINVALOne of the parameters was invalid.       The following errors are fortracefs_instance_set_affinity() andtracefs_instance_set_affinity_set():ENOMEMMemory allocation error.ENODEVdynamic events of requested type are not configured for the       running kernel.       The following errors are just fortracefs_instance_set_affinity()EACCESThecpu_str was modified by another thread when processing       it.

EXAMPLE        top

           #include <sched.h>           #include <stdio.h>           #include <stdlib.h>           #include <tracefs.h>           int main (int argc, char **argv)           {                   struct trace_seq seq;                   cpu_set_t *set;                   size_t set_size;                   char *c;                   int cpu1;                   int cpu2;                   int i;                   c = tracefs_instance_get_affinity(NULL);                   printf("The affinity was %s\n", c);                   free(c);                   if (argc < 2) {                           tracefs_instance_set_affinity(NULL, NULL);                           exit(0);                   }                   /* Show example using a set */                   if (argc == 2 && !strchr(argv[1],',')) {                           cpu1 = atoi(argv[1]);                           c = strchr(argv[1], '-');                           if (c++)                                   cpu2 = atoi(c);                           else                                   cpu2 = cpu1;                           if (cpu2 < cpu1) {                                   fprintf(stderr, "Invalid CPU range\n");                                   exit(-1);                           }                           set = CPU_ALLOC(cpu2 + 1);                           set_size = CPU_ALLOC_SIZE(cpu2 + 1);                           CPU_ZERO_S(set_size, set);                           for ( ; cpu1 <= cpu2; cpu1++)                                   CPU_SET(cpu1, set);                           tracefs_instance_set_affinity_set(NULL, set, set_size);                           CPU_FREE(set);                           exit(0);                   }                   trace_seq_init(&seq);                   for (i = 1; i < argc; i++) {                           if (i > 1)                                   trace_seq_putc(&seq, ',');                           trace_seq_puts(&seq, argv[i]);                   }                   trace_seq_terminate(&seq);                   tracefs_instance_set_affinity(NULL, seq.buffer);                   trace_seq_destroy(&seq);                   exit(0);                   return 0;           }

FILES        top

tracefs.h                   Header file to include in order to have access to the library APIs.-ltracefs                   Linker switch to add when building a program that uses the library.

SEE ALSO        top

libtracefs(3),libtraceevent(3),trace-cmd(1)

AUTHOR        top

Steven Rostedt<rostedt@goodmis.org[1]>Tzvetomir Stoyanov<tz.stoyanov@gmail.com[2]>

REPORTING BUGS        top

       Report bugs to <linux-trace-devel@vger.kernel.org[3]>

LICENSE        top

       libtracefs is Free Software licensed under the GNU LGPL 2.1

RESOURCES        top

https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/

COPYING        top

       Copyright (C) 2020 VMware, Inc. Free use of this software is       granted under the terms of the GNU Public License (GPL).

NOTES        top

        1. rostedt@goodmis.org           mailto:rostedt@goodmis.org        2. tz.stoyanov@gmail.com           mailto:tz.stoyanov@gmail.com        3. linux-trace-devel@vger.kernel.org           mailto:linux-trace-devel@vger.kernel.org

COLOPHON        top

       This page is part of thelibtracefs (Linux kernel trace file       system library) project.  Information about the project can be       found at ⟨https://www.trace-cmd.org/⟩.  If you have a bug report       for this manual page, see ⟨https://www.trace-cmd.org/⟩.  This page       was obtained from the project's upstream Git repository       ⟨https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git⟩ on       2025-08-11.  (At that time, the date of the most recent commit       that was found in the repository was 2025-06-02.)  If you discover       any rendering problems in this HTML version of the page, or you       believe there is a better or more up-to-date source for the page,       or you have corrections or improvements to the information in this       COLOPHON (which isnot part of the original manual page), send a       mail to man-pages@man7.orglibtracefs 1.7.0                12/22/2023LIBTRACEFS(3)


HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp