1 /** 2 * @file fg_affinity.h 3 * @brief CPU affinity routines used by Flowgrind 4 */ 5 6 /* 7 * Copyright (C) 2014 Alexander Zimmermann <alexander.zimmermann@netapp.com> 8 * 9 * This file is part of Flowgrind. 10 * 11 * Flowgrind is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation, either version 3 of the License, or 14 * (at your option) any later version. 15 * 16 * Flowgrind is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with Flowgrind. If not, see <http://www.gnu.org/licenses/>. 23 * 24 */ 25 26 #ifndef _FG_AFFINITY_H_ 27 #define _FG_AFFINITY_H_ 28 29 #ifdef HAVE_CONFIG_H 30 #include "config.h" 31 #endif /* HAVE_CONFIG_H */ 32 33 #include <pthread.h> 34 35 /** Query type for get_ncores(). */ 36 enum ncore_query { 37 /** Total number of processors configured. */ 38 NCORE_CONFIG = 0, 39 /** Processors available to the current process. */ 40 NCORE_CURRENT 41 }; 42 43 /** 44 * Return either the total number of configured or available cores. 45 * 46 * @param[in] query indicates if either the configured or available cores 47 * should be be returned @see enum nproc_query 48 * @return return number of processors on success, or -1 for failure 49 */ 50 int get_ncores(enum ncore_query query); 51 52 /** 53 * Set CPU affinity of the thread @p thread to the core @p core. 54 * 55 * @param[in] thread thread ID 56 * @param[in] core core to which thread @p thread will be bounded 57 * @return return 0 for success, or -1 for failure 58 */ 59 int pthread_setaffinity(pthread_t thread, unsigned core); 60 61 /** 62 * Returns the CPU affinity of thread @p thread in the buffer pointed to by 63 * @p core. 64 * 65 * @param[in] thread thread ID 66 * @param[out] core core to which thread @p thread is bounded 67 * @return return 0 for success, or -1 for failure 68 */ 69 int pthread_getaffinity(pthread_t thread, unsigned *core); 70 71 #endif /* _FG_AFFINITY_H_ */ 72