'\" t .\" Title: libtracefs .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 10/08/2022 .\" Manual: libtracefs Manual .\" Source: libtracefs 1.5.0 .\" Language: English .\" .TH "LIBTRACEFS" "3" "10/08/2022" "libtracefs 1\&.5\&.0" "libtracefs Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" 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\&. .SH "SYNOPSIS" .sp .nf \fB#include \fR int \fBtracefs_instance_set_affinity\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIcpu_str\fR); int \fBtracefs_instance_set_affinity_set\fR(struct tracefs_instance *\fIinstance\fR, cpu_set_t *\fIset\fR, size_t \fIset_size\fR); int \fBtracefs_instance_set_affinity_raw\fR(struct tracefs_instance *\fIinstance\fR, const char *\fImask\fR); char *\fBtracefs_instance_get_affinity\fR(struct tracefs_instance *\fIinstance\fR); int \fBtracefs_instance_get_affinity_set\fR(struct tracefs_instance *\fIinstance\fR, cpu_set_t *\fIset\fR, size_t \fIset_size\fR); char *\fBtracefs_instance_get_affinity_raw\fR(struct tracefs_instance *\fIinstance\fR); .fi .SH "DESCRIPTION" .sp These functions set or retrieve the CPU affinity that limits what CPUs will have tracing enabled for a given instance defined by the \fIinstance\fR parameter\&. If \fIinstance\fR is NULL, then the top level instance is affected\&. .sp The \fBtracefs_instance_set_affinity()\fR function takes a string \fIcpu_str\fR that is a list of CPUs to set the affinity for\&. If \fIcpu_str\fR is NULL, then all the CPUs in the system will be set\&. The format of \fIcpu_str\fR is a comma delimited string of decimal numbers with no spaces\&. A range may be specified by a hyphen\&. .sp For example: "1,4,6\-8" .sp 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\&. .sp The \fBtracefs_instance_set_affinity_set()\fR function takes a CPU set defined by \fBCPU_SET\fR(3)\&. The size of the set defined by \fIset_size\fR is the size in bytes of \fIset\fR\&. If \fIset\fR is NULL then all the CPUs on the system will be set, and \fIset_size\fR is ignored\&. .sp The \fBtracefs_instance_set_affinity_raw()\fR 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: .sp .if n \{\ .RS 4 .\} .nf "100,000007fe" .fi .if n \{\ .RE .\} .sp Where the above is a hex representation of bits 1\-10 and bit 40 being set\&. .sp The \fBtracefs_instance_get_affinity()\fR will retrieve the affinity in a human readable form\&. .sp For example: "1,4,6\-8" .sp The string returned must be freed with \fBfree\fR(3)\&. .sp The \fBtracefs_instance_get_affinity_set()\fR will set all the bits in the passed in cpu set (from \fBCPU_SET\fR(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\&. .sp The \fBtracefs_instance_get_affinity_raw()\fR will simply read the instance tracing_cpumask and return that string\&. The returned string must be freed with \fBfree\fR(3)\&. .SH "RETURN VALUE" .sp All the set functions return 0 on success and \-1 on error\&. .sp The functions \fBtracefs_instance_get_affinity()\fR and \fBtracefs_instance_get_affinity_raw()\fR returns an allocated string that must be freed with \fBfree\fR(3), or NULL on error\&. .sp The function \fBtracefs_instance_get_affinity_set()\fR returns the number of CPUs that were found set, or \-1 on error\&. .SH "ERRORS" .sp The following errors are for all the above calls: .sp \fBEFBIG\fR if a CPU is set that is greater than what is in the system\&. .sp \fBEINVAL\fR One of the parameters was invalid\&. .sp The following errors are for \fBtracefs_instance_set_affinity\fR() and \fBtracefs_instance_set_affinity_set\fR(): .sp \fBENOMEM\fR Memory allocation error\&. .sp \fBENODEV\fR dynamic events of requested type are not configured for the running kernel\&. .sp The following errors are just for \fBtracefs_instance_set_affinity\fR() .sp \fBEACCES\fR The \fIcpu_str\fR was modified by another thread when processing it\&. .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf #include #include #include #include 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\en", 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],\*(Aq,\*(Aq)) { cpu1 = atoi(argv[1]); c = strchr(argv[1], \*(Aq\-\*(Aq); if (c++) cpu2 = atoi(c); else cpu2 = cpu1; if (cpu2 < cpu1) { fprintf(stderr, "Invalid CPU range\en"); 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, \*(Aq,\*(Aq); 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; } .fi .if n \{\ .RE .\} .SH "FILES" .sp .if n \{\ .RS 4 .\} .nf \fBtracefs\&.h\fR Header file to include in order to have access to the library APIs\&. \fB\-ltracefs\fR Linker switch to add when building a program that uses the library\&. .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBlibtracefs\fR(3), \fBlibtraceevent\fR(3), \fBtrace\-cmd\fR(1) .SH "AUTHOR" .sp .if n \{\ .RS 4 .\} .nf \fBSteven Rostedt\fR <\m[blue]\fBrostedt@goodmis\&.org\fR\m[]\&\s-2\u[1]\d\s+2> \fBTzvetomir Stoyanov\fR <\m[blue]\fBtz\&.stoyanov@gmail\&.com\fR\m[]\&\s-2\u[2]\d\s+2> .fi .if n \{\ .RE .\} .SH "REPORTING BUGS" .sp Report bugs to <\m[blue]\fBlinux\-trace\-devel@vger\&.kernel\&.org\fR\m[]\&\s-2\u[3]\d\s+2> .SH "LICENSE" .sp libtracefs is Free Software licensed under the GNU LGPL 2\&.1 .SH "RESOURCES" .sp \m[blue]\fBhttps://git\&.kernel\&.org/pub/scm/libs/libtrace/libtracefs\&.git/\fR\m[] .SH "COPYING" .sp Copyright (C) 2020 VMware, Inc\&. Free use of this software is granted under the terms of the GNU Public License (GPL)\&. .SH "NOTES" .IP " 1." 4 rostedt@goodmis.org .RS 4 \%mailto:rostedt@goodmis.org .RE .IP " 2." 4 tz.stoyanov@gmail.com .RS 4 \%mailto:tz.stoyanov@gmail.com .RE .IP " 3." 4 linux-trace-devel@vger.kernel.org .RS 4 \%mailto:linux-trace-devel@vger.kernel.org .RE