-
Notifications
You must be signed in to change notification settings - Fork 6
jappavoo
Status:
committed a bunch of changes to build-reorg to get things working on both platforms. In Process: started to think about and get code ready so that unix lrt pic’s are bound to a physical cores of the unix system. Code on OSX and linux is significantly different.
This is some of the OSX code I am playing with: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/sysctl.h> #include <mach/thread_policy.h> #include <pthread.h>
pthread_t *tids = NULL; int lrt_cores_num = 0;
int static lrt_cores_num_phys(void) { #ifdef __APPLE__ // based on doc I could find on net about OSX/mach internals int mib[4], numcores; size_t len, size;
len = 4; sysctlnametomib("hw.physicalcpu_max", mib, &len);
size = sizeof(numcores); if (sysctl(mib, len, &numcores, &size, NULL, 0)==-1) { perror("sysctl"); return -1; } return numcores; #else
#endif }
int lrt_cores_numcores(void) { return lrt_cores_num; }
int lrt_cores_init(int num) { if (num==0) lrt_cores_num = lrt_cores_num_phys(); else lrt_cores_num = num; }
int lrt_cores_start(int id, void *(*func)(void *), void *arg); { int numcores, physicalcore, pid, rc; thread_affinity_policy_data_t affinityinfo;
numcores = lrt_numcores(); pid = id % numcores;
if (id < 0 || id >= numcores) return -1;
if (tids==NULL) tids = (pthread_t *)malloc(numcores * sizeof(pthread_t));
rc = pthread_create_suspended_np(&tid[id], NULL, func, arg); if (rc != 0) { perror("pthread_create_suspended_np"); return -1; }
affinityinfo.affinity_tag = pid+1; rc = thread_policy_set(pthread_mach_thread_np(tids[id]), THREAD_AFFINITY_POLICY, &affinityinfo, THREAD_AFFINITY_POLICY_COUNT); if (rc != KERN_SUCCESS) { perror("thread_policy_set"); return -1; }
thread_resume(pthread_mach_thread_np(tids[id])); }
void * procfunc(void *arg) { long long i=(long long)arg;
printf("%s: %lld: started\n", __func__, i); while (1) { sleep(2); printf("%lld\n", i); } return NULL; }
int main(int argc, char **argv) { int numcores, i;
lrt_cores_init(0); numcores = lrt_cores_numcores();
printf("numcores=%d\n", numcores); for (i=0; i<numcores; i++) { arg=i; lrt_cores_start(i, procfunc, (void *)arg); }
for (i=0; i<numcores; i++) pthread_join(tids[i], NULL)
return 0; }
This triggered a discussion of whether we should add support now for more dynamic notions of adding an subtracting event locations and how we should identify the event locations and the set of current locations.
Still need to send not to Jimi, Ron, Jan, Amos about bootloaders/firmware
The process below builds the source on the current system for 3 debug levels
checkout cd into tree contrib/jappavoo/mkbuild make -C ../build subsequent make -C ../build Build the same source tree but on a new system cd into tree contrib/jappavoo/mkbuild make -C ../build
This will not harm another systems build of the same tree as the build dir has sub dirs for each system type computed via uname -s