Skip Menu |

This queue is for tickets about the Sys-CpuAffinity CPAN distribution.

Report information
The Basics
Id: 94560
Status: resolved
Priority: 0/
Queue: Sys-CpuAffinity

People
Owner: MOB [...] cpan.org
Requestors: Marcin.Wielgosz [...] imc.ch
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in:
  • 1.08
  • 1.09

Attachments
A8621E59-23EC-4528-905B-AB181A79DD22[3].png



Subject: Segfaults on some fc13
Date: Wed, 9 Apr 2014 11:57:34 +0000
To: "bug-Sys-CpuAffinity [...] rt.cpan.org" <bug-Sys-CpuAffinity [...] rt.cpan.org>
From: Marcin Wielgosz <Marcin.Wielgosz [...] imc.ch>
Hi, I’ve been using highly modified version of your module and I found out that it tends to segfault on some of FC13 boxes(Linux and distribution is irrelevant here). Program received signal SIGSEGV, Segmentation fault. 0x00000035e1682d84 in memset () from /lib64/libc.so.6 (gdb) backtrace #0 0x00000035e1682d84 in memset () from /lib64/libc.so.6 #1 0x00000035e16c7dc4 in sched_getaffinity@@GLIBC_2.3.4 () from /lib64/libc.so.6 Here is a part of linux-sched_getaffinity.xs: if(debug_flag) fprintf(stderr,"getaffinity0\n"); _set1 = &_set2; if(debug_flag) fprintf(stderr,"getaffinity1 pid=%d size=%d cpuset=0x%d\n", (int) pid, (int) CPU_SETSIZE, (int) _set1); z = sched_getaffinity((pid_t) pid, CPU_SETSIZE, _set1); if(debug_flag) fprintf(stderr,"getaffinity2\n”); And some facts from /usr/include/bits/sched.h: # define __CPU_SETSIZE 1024 typedef unsigned long int __cpu_mask; // size 4B # define __NCPUBITS (8 * sizeof (__cpu_mask)) // 32 typedef struct { __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS]; // size 4B * [1024/32] = 128B } cpu_set_t; So, 'sched_getaffinity((pid_t) pid, CPU_SETSIZE, _set1)’ requests libc to fill out _set1(128B) and zero the rest up to 1024nth byte which is beyond the size of the structure and leads to segfaults. I’d recommend to replace CPU_SETSIZE with sizeof(_set2); Secondly, this module works up to 32 cores and needs to be rewritten. Marcin Wielgosz System Integration Engineer [Description: Description: http://www.imc.nl/Global/Logos/IMC-logo-rgb_150.gif] IMC financial markets | Poststrasse 20, 6300, Zug, Switzerland | www.imc.nl <http://www.imc.nl/> T +41 (0)41 560 32 05 | M +41 (0)79 570 03 05 | E Marcin.Wielgosz@imc.ch<mailto:Marcin.Wielgosz@imc.ch> Show quoted text
________________________________ The information in this e-mail is intended only for the person or entity to which it is addressed. It may contain confidential and /or privileged material. If someone other than the intended recipient should receive this e-mail, he / she shall not be entitled to read, disseminate, disclose or duplicate it. If you receive this e-mail unintentionally, please inform us immediately by "reply" and then delete it from your system. Although this information has been compiled with great care, neither IMC Financial Markets & Asset Management nor any of its related entities shall accept any responsibility for any errors, omissions or other inaccuracies in this information or for the consequences thereof, nor shall it be bound in any way by the contents of this e-mail or its attachments. In the event of incomplete or incorrect transmission, please return the e-mail to the sender and permanently delete this message and any attachments. Messages and attachments are scanned for all known viruses. Always scan attachments before opening them.
A8621E59-23EC-4528-905B-AB181A79DD22[3].png
I finally have a system with >32 cores to play with. My call to sched_getaffinity and the way I iterated through the bits of the cpu mask were cargo-culted. Doing some more research (and cargo-culting off a more recent set of examples about how to use these functions), I see I should pass sizeof(cpu_set_t) to sched_getaffinity and not CPU_SETSIZE , and I should iterate __NCPUBITS times in the cpu mask, not CPU_SETSIZE (which is way too large) or 32 (which is sometimes too small). The pending fix should address the segmentation faults observed and remove the limitation on support of systems with more than 32 cores.
Improved handling of systems with more than 32 cores in v1.08 and v1.09