200-avoid-glib.patch (11514B)
1 Revert upstream commit d1993bcde2a524346a9508754671f096ec129ad1 2 to avoid glib dependency. That commit polluted the main code 3 with glib types. 4 5 --- a/irqbalance.h 6 +++ b/irqbalance.h 7 @@ -8,7 +8,6 @@ 8 9 #include <stdint.h> 10 #include <glib.h> 11 -#include <glib-unix.h> 12 #include <syslog.h> 13 #include <limits.h> 14 15 @@ -63,7 +62,6 @@ extern GList *packages; 16 extern GList *cache_domains; 17 extern GList *cpus; 18 extern int numa_avail; 19 -extern GList *cl_banned_irqs; 20 21 extern int debug_mode; 22 extern int journal_logging; 23 @@ -171,7 +169,5 @@ extern unsigned int log_mask; 24 }while(0) 25 #endif /* HAVE_LIBSYSTEMD */ 26 27 -#define SOCKET_PATH "irqbalance" 28 - 29 #endif /* __INCLUDE_GUARD_IRQBALANCE_H_ */ 30 31 --- a/irqbalance.c 32 +++ b/irqbalance.c 33 @@ -31,8 +31,6 @@ 34 #include <time.h> 35 #include <sys/types.h> 36 #include <sys/stat.h> 37 -#include <sys/socket.h> 38 -#include <sys/un.h> 39 #include <fcntl.h> 40 #ifdef HAVE_GETOPT_LONG 41 #include <getopt.h> 42 @@ -44,7 +42,6 @@ 43 #include "irqbalance.h" 44 45 volatile int keep_going = 1; 46 -int socket_fd; 47 int one_shot_mode; 48 int debug_mode; 49 int foreground_mode; 50 @@ -61,9 +58,6 @@ char *banscript = NULL; 51 char *polscript = NULL; 52 long HZ; 53 int sleep_interval = SLEEP_INTERVAL; 54 -GMainLoop *main_loop; 55 - 56 -char *banned_cpumask_from_ui = NULL; 57 58 static void sleep_approx(int seconds) 59 { 60 @@ -236,224 +230,22 @@ static void force_rebalance_irq(struct i 61 info->assigned_obj = NULL; 62 } 63 64 -gboolean handler(gpointer data __attribute__((unused))) 65 +static void handler(int signum) 66 { 67 + (void)signum; 68 keep_going = 0; 69 - g_main_loop_quit(main_loop); 70 - return TRUE; 71 } 72 73 -gboolean force_rescan(gpointer data __attribute__((unused))) 74 +static void force_rescan(int signum) 75 { 76 + (void)signum; 77 if (cycle_count) 78 need_rescan = 1; 79 - return TRUE; 80 -} 81 - 82 -gboolean scan(gpointer data) 83 -{ 84 - log(TO_CONSOLE, LOG_INFO, "\n\n\n-----------------------------------------------------------------------------\n"); 85 - clear_work_stats(); 86 - parse_proc_interrupts(); 87 - parse_proc_stat(); 88 - 89 - 90 - /* cope with cpu hotplug -- detected during /proc/interrupts parsing */ 91 - if (need_rescan) { 92 - need_rescan = 0; 93 - cycle_count = 0; 94 - log(TO_CONSOLE, LOG_INFO, "Rescanning cpu topology \n"); 95 - clear_work_stats(); 96 - 97 - free_object_tree(); 98 - build_object_tree(); 99 - for_each_irq(NULL, force_rebalance_irq, NULL); 100 - parse_proc_interrupts(); 101 - parse_proc_stat(); 102 - sleep_approx(sleep_interval); 103 - clear_work_stats(); 104 - parse_proc_interrupts(); 105 - parse_proc_stat(); 106 - } 107 - 108 - if (cycle_count) 109 - update_migration_status(); 110 - 111 - calculate_placement(); 112 - activate_mappings(); 113 - 114 - if (debug_mode) 115 - dump_tree(); 116 - if (one_shot_mode) 117 - keep_going = 0; 118 - cycle_count++; 119 - 120 - if (data != &sleep_interval) { 121 - data = &sleep_interval; 122 - g_timeout_add_seconds(sleep_interval, scan, data); 123 - return FALSE; 124 - } 125 - 126 - if (keep_going) 127 - return TRUE; 128 - else 129 - return FALSE; 130 -} 131 - 132 -void get_irq_data(struct irq_info *irq, void *data) 133 -{ 134 - sprintf(data + strlen(data), 135 - "IRQ %d LOAD %lu DIFF %lu CLASS %d ", irq->irq, irq->load, 136 - (irq->irq_count - irq->last_irq_count), irq->class); 137 -} 138 - 139 -void get_object_stat(struct topo_obj *object, void *data) 140 -{ 141 - char irq_data[1024] = "\0"; 142 - 143 - if (g_list_length(object->interrupts) > 0) { 144 - for_each_irq(object->interrupts, get_irq_data, irq_data); 145 - } 146 - sprintf(data + strlen(data), "TYPE %d NUMBER %d LOAD %lu SAVE_MODE %d %s", 147 - object->obj_type, object->number, object->load, 148 - object->powersave_mode, irq_data); 149 - if (object->obj_type != OBJ_TYPE_CPU) { 150 - for_each_object(object->children, get_object_stat, data); 151 - } 152 -} 153 - 154 -gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attribute__((unused))) 155 -{ 156 - char buff[500]; 157 - int sock; 158 - int recv_size = 0; 159 - int valid_user = 0; 160 - 161 - struct iovec iov = { buff, 500 }; 162 - struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0, 0 }; 163 - msg.msg_control = malloc(CMSG_SPACE(sizeof(struct ucred))); 164 - msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred)); 165 - 166 - struct cmsghdr *cmsg; 167 - 168 - if (condition == G_IO_IN) { 169 - sock = accept(fd, NULL, NULL); 170 - if (sock < 0) { 171 - log(TO_ALL, LOG_WARNING, "Connection couldn't be accepted.\n"); 172 - return TRUE; 173 - } 174 - if ((recv_size = recvmsg(sock, &msg, 0)) < 0) { 175 - log(TO_ALL, LOG_WARNING, "Error while receiving data.\n"); 176 - return TRUE; 177 - } 178 - cmsg = CMSG_FIRSTHDR(&msg); 179 - if ((cmsg->cmsg_level == SOL_SOCKET) && 180 - (cmsg->cmsg_type == SCM_CREDENTIALS)) { 181 - struct ucred *credentials = (struct ucred *) CMSG_DATA(cmsg); 182 - if (!credentials->uid) { 183 - valid_user = 1; 184 - } 185 - } 186 - if (!valid_user) { 187 - log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n"); 188 - return TRUE; 189 - } 190 - 191 - if (!strncmp(buff, "stats", strlen("stats"))) { 192 - char stats[2048] = "\0"; 193 - for_each_object(numa_nodes, get_object_stat, stats); 194 - send(sock, stats, strlen(stats), 0); 195 - } 196 - if (!strncmp(buff, "settings ", strlen("settings "))) { 197 - if (!(strncmp(buff + strlen("settings "), "sleep ", 198 - strlen("sleep ")))) { 199 - char *sleep_string = malloc( 200 - sizeof(char) * (recv_size - strlen("settings sleep "))); 201 - strncpy(sleep_string, buff + strlen("settings sleep "), 202 - recv_size - strlen("settings sleep ")); 203 - int new_iterval = strtoul(sleep_string, NULL, 10); 204 - if (new_iterval >= 1) { 205 - sleep_interval = new_iterval; 206 - } 207 - } else if (!(strncmp(buff + strlen("settings "), "ban irqs ", 208 - strlen("ban irqs ")))) { 209 - char *end; 210 - char *irq_string = malloc( 211 - sizeof(char) * (recv_size - strlen("settings ban irqs "))); 212 - strncpy(irq_string, buff + strlen("settings ban irqs "), 213 - recv_size - strlen("settings ban irqs ")); 214 - g_list_free_full(cl_banned_irqs, free); 215 - cl_banned_irqs = NULL; 216 - need_rescan = 1; 217 - if (!strncmp(irq_string, "NONE", strlen("NONE"))) { 218 - return TRUE; 219 - } 220 - int irq = strtoul(irq_string, &end, 10); 221 - do { 222 - add_cl_banned_irq(irq); 223 - } while((irq = strtoul(end, &end, 10))); 224 - } else if (!(strncmp(buff + strlen("settings "), "cpus ", 225 - strlen("cpus")))) { 226 - char *cpu_ban_string = malloc( 227 - sizeof(char) * (recv_size - strlen("settings cpus "))); 228 - strncpy(cpu_ban_string, buff + strlen("settings cpus "), 229 - recv_size - strlen("settings cpus ")); 230 - banned_cpumask_from_ui = strtok(cpu_ban_string, " "); 231 - if (!strncmp(banned_cpumask_from_ui, "NULL", strlen("NULL"))) { 232 - banned_cpumask_from_ui = NULL; 233 - } 234 - need_rescan = 1; 235 - } 236 - } 237 - if (!strncmp(buff, "setup", strlen("setup"))) { 238 - char setup[2048] = "\0"; 239 - snprintf(setup, 2048, "SLEEP %d ", sleep_interval); 240 - if(g_list_length(cl_banned_irqs) > 0) { 241 - for_each_irq(cl_banned_irqs, get_irq_data, setup); 242 - } 243 - char banned[512]; 244 - cpumask_scnprintf(banned, 512, banned_cpus); 245 - snprintf(setup + strlen(setup), 2048 - strlen(setup), 246 - "BANNED %s", banned); 247 - send(sock, setup, strlen(setup), 0); 248 - } 249 - 250 - close(sock); 251 - } 252 - return TRUE; 253 -} 254 - 255 -int init_socket(char *socket_name) 256 -{ 257 - struct sockaddr_un addr; 258 - memset(&addr, 0, sizeof(struct sockaddr_un)); 259 - 260 - socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0); 261 - if (socket_fd < 0) { 262 - log(TO_ALL, LOG_WARNING, "Socket couldn't be created.\n"); 263 - return 1; 264 - } 265 - 266 - addr.sun_family = AF_UNIX; 267 - addr.sun_path[0] = '\0'; 268 - strncpy(addr.sun_path + 1, socket_name, strlen(socket_name)); 269 - if (bind(socket_fd, (struct sockaddr *)&addr, 270 - sizeof(sa_family_t) + strlen(socket_name) + 1) < 0) { 271 - log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the socket.\n"); 272 - return 1; 273 - } 274 - int optval = 1; 275 - if (setsockopt(socket_fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) < 0) { 276 - log(TO_ALL, LOG_WARNING, "Unable to set socket options.\n"); 277 - return 1; 278 - } 279 - listen(socket_fd, 1); 280 - g_unix_fd_add(socket_fd, G_IO_IN, sock_handle, NULL); 281 - return 0; 282 } 283 284 int main(int argc, char** argv) 285 { 286 + struct sigaction action, hupaction; 287 sigset_t sigset, old_sigset; 288 289 sigemptyset(&sigset); 290 @@ -553,11 +345,19 @@ int main(int argc, char** argv) 291 } 292 } 293 294 - g_unix_signal_add(SIGINT, handler, NULL); 295 - g_unix_signal_add(SIGTERM, handler, NULL); 296 - g_unix_signal_add(SIGUSR1, handler, NULL); 297 - g_unix_signal_add(SIGUSR2, handler, NULL); 298 - g_unix_signal_add(SIGHUP, force_rescan, NULL); 299 + action.sa_handler = handler; 300 + sigemptyset(&action.sa_mask); 301 + action.sa_flags = 0; 302 + sigaction(SIGINT, &action, NULL); 303 + sigaction(SIGTERM, &action, NULL); 304 + sigaction(SIGUSR1, &action, NULL); 305 + sigaction(SIGUSR2, &action, NULL); 306 + 307 + hupaction.sa_handler = force_rescan; 308 + sigemptyset(&hupaction.sa_mask); 309 + hupaction.sa_flags = 0; 310 + sigaction(SIGHUP, &hupaction, NULL); 311 + 312 sigprocmask(SIG_SETMASK, &old_sigset, NULL); 313 314 #ifdef HAVE_LIBCAP_NG 315 @@ -566,32 +366,58 @@ int main(int argc, char** argv) 316 capng_lock(); 317 capng_apply(CAPNG_SELECT_BOTH); 318 #endif 319 + 320 for_each_irq(NULL, force_rebalance_irq, NULL); 321 322 parse_proc_interrupts(); 323 parse_proc_stat(); 324 325 - char socket_name[64]; 326 - snprintf(socket_name, 64, "%s%d.sock", SOCKET_PATH, getpid()); 327 + while (keep_going) { 328 + sleep_approx(sleep_interval); 329 + log(TO_CONSOLE, LOG_INFO, "\n\n\n-----------------------------------------------------------------------------\n"); 330 331 - if (init_socket(socket_name)) { 332 - return EXIT_FAILURE; 333 - } 334 - main_loop = g_main_loop_new(NULL, FALSE); 335 - int *last_interval = &sleep_interval; 336 - g_timeout_add_seconds(sleep_interval, scan, last_interval); 337 - g_main_loop_run(main_loop); 338 339 - g_main_loop_quit(main_loop); 340 + clear_work_stats(); 341 + parse_proc_interrupts(); 342 + parse_proc_stat(); 343 + 344 + /* cope with cpu hotplug -- detected during /proc/interrupts parsing */ 345 + if (need_rescan) { 346 + need_rescan = 0; 347 + cycle_count = 0; 348 + log(TO_CONSOLE, LOG_INFO, "Rescanning cpu topology \n"); 349 + clear_work_stats(); 350 + 351 + free_object_tree(); 352 + build_object_tree(); 353 + for_each_irq(NULL, force_rebalance_irq, NULL); 354 + parse_proc_interrupts(); 355 + parse_proc_stat(); 356 + sleep_approx(sleep_interval); 357 + clear_work_stats(); 358 + parse_proc_interrupts(); 359 + parse_proc_stat(); 360 + } 361 + 362 + if (cycle_count) 363 + update_migration_status(); 364 + 365 + calculate_placement(); 366 + activate_mappings(); 367 368 + if (debug_mode) 369 + dump_tree(); 370 + if (one_shot_mode) 371 + keep_going = 0; 372 + cycle_count++; 373 + 374 + } 375 free_object_tree(); 376 free_cl_opts(); 377 378 /* Remove pidfile */ 379 if (!foreground_mode && pidfile) 380 unlink(pidfile); 381 - /* Remove socket */ 382 - close(socket_fd); 383 384 return EXIT_SUCCESS; 385 } 386 --- a/cputree.c 387 +++ b/cputree.c 388 @@ -38,7 +38,6 @@ 389 390 #include "irqbalance.h" 391 392 -extern char *banned_cpumask_from_ui; 393 394 GList *cpus; 395 GList *cache_domains; 396 @@ -77,15 +76,11 @@ static void setup_banned_cpus(void) 397 cpus_clear(nohz_full); 398 399 /* A manually specified cpumask overrides auto-detection. */ 400 - if (banned_cpumask_from_ui != NULL) { 401 - cpulist_parse(banned_cpumask_from_ui, 402 - strlen(banned_cpumask_from_ui), banned_cpus); 403 - goto out; 404 - } 405 if (getenv("IRQBALANCE_BANNED_CPUS")) { 406 cpumask_parse_user(getenv("IRQBALANCE_BANNED_CPUS"), strlen(getenv("IRQBALANCE_BANNED_CPUS")), banned_cpus); 407 goto out; 408 } 409 + 410 file = fopen("/sys/devices/system/cpu/isolated", "r"); 411 if (file) { 412 if (getline(&line, &size, file) > 0) { 413 @@ -117,8 +112,6 @@ out: 414 log(TO_CONSOLE, LOG_INFO, "Isolated CPUs: %s\n", buffer); 415 cpumask_scnprintf(buffer, 4096, nohz_full); 416 log(TO_CONSOLE, LOG_INFO, "Adaptive-ticks CPUs: %s\n", buffer); 417 - cpumask_scnprintf(buffer, 4096, banned_cpus); 418 - log(TO_CONSOLE, LOG_INFO, "Banned CPUs: %s\n", buffer); 419 } 420 421 static struct topo_obj* add_cache_domain_to_package(struct topo_obj *cache,