Merge lp:~epics-core/epics-base/get-cpus into lp:~epics-core/epics-base/3.15

Proposed by Ralph Lange on 2013-03-28
Status: Merged
Merged at revision: 12480
Proposed branch: lp:~epics-core/epics-base/get-cpus
Merge into: lp:~epics-core/epics-base/3.15
Diff against target: 131 lines (+50/-3)
7 files modified
.bzrignore (+1/-0)
src/libCom/osi/epicsThread.h (+2/-1)
src/libCom/osi/os/RTEMS/osdThread.c (+9/-0)
src/libCom/osi/os/WIN32/osdThread.c (+12/-0)
src/libCom/osi/os/posix/osdThread.c (+16/-1)
src/libCom/osi/os/vxWorks/osdThread.c (+5/-0)
src/libCom/test/epicsThreadTest.cpp (+5/-1)
To merge this branch: bzr merge lp:~epics-core/epics-base/get-cpus
Reviewer Review Type Date Requested Status
Andrew Johnson 2013-03-28 Approve on 2014-05-19
Review via email: mp+155967@code.launchpad.net

Description of the change

Add int epicsThreadGetCPUs() to the epicsThread API.

epicsThreadGetCPUs() returns the number of logical CPUs that are available for the IOC. On systems that use Hyper-Threading, this number may be up to twice the number of physical cores.

The Posix and WIN32 implementations are returning the number of CPUs available for the process, which may be limited by the system.
For the time being, vxWorks just returns 1.

Only tested for Linux. The implementations for RTEMS, vxWorks and WIN32 need testing, please...

To post a comment you must log in.
mdavidsaver (mdavidsaver) wrote :

I'd certainly like to see this merged. For possilbly more complete posix and win32 implementations see:

http://bazaar.launchpad.net/~epics-core/epics-base/thread-pool/revision/12255

Andrew Johnson (anj) wrote :

I'd prefer Ralph's routine name with Michael's implementations on WIN32 & Posix (and his test).

lp:~epics-core/epics-base/get-cpus updated on 2014-05-18
12412. By Ralph Lange on 2014-05-18

.bzrignore: add QtCreator project files

12413. By Ralph Lange on 2014-05-18

libCom/osi: use epicsThreadGetCPUs implementation from thread-pool branch (posix, WIN32)

Ralph Lange (ralph-lange) wrote :

I changed the branch in line with Andrew's preferences.

Andrew Johnson (anj) wrote :

Looks good and works for me, merging — thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-06-22 23:16:26 +0000
3+++ .bzrignore 2014-05-18 15:26:56 +0000
4@@ -6,3 +6,4 @@
5 ./include
6 ./templates
7 **/O.*
8+./QtC-*
9
10=== modified file 'src/libCom/osi/epicsThread.h'
11--- src/libCom/osi/epicsThread.h 2012-07-06 21:33:10 +0000
12+++ src/libCom/osi/epicsThread.h 2014-05-18 15:26:56 +0000
13@@ -3,7 +3,7 @@
14 * National Laboratory.
15 * Copyright (c) 2002 The Regents of the University of California, as
16 * Operator of Los Alamos National Laboratory.
17-* Copyright (c) 2012 ITER Organization
18+* Copyright (c) 2013 ITER Organization.
19 * EPICS BASE is distributed subject to a Software License Agreement found
20 * in file LICENSE that is included with this distribution.
21 \*************************************************************************/
22@@ -85,6 +85,7 @@
23 epicsShareFunc double epicsShareAPI epicsThreadSleepQuantum(void);
24 epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetIdSelf(void);
25 epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetId(const char *name);
26+epicsShareFunc int epicsThreadGetCPUs(void);
27
28 epicsShareFunc const char * epicsShareAPI epicsThreadGetNameSelf(void);
29
30
31=== modified file 'src/libCom/osi/os/RTEMS/osdThread.c'
32--- src/libCom/osi/os/RTEMS/osdThread.c 2012-07-31 19:04:38 +0000
33+++ src/libCom/osi/os/RTEMS/osdThread.c 2014-05-18 15:26:56 +0000
34@@ -718,3 +718,12 @@
35
36 return 1.0 / rtemsTicksPerSecond_double;
37 }
38+
39+epicsShareFunc int epicsThreadGetCPUs(void)
40+{
41+#if defined(RTEMS_SMP)
42+ return rtems_smp_get_number_of_processors();
43+#else
44+ return 1;
45+#endif
46+}
47
48=== modified file 'src/libCom/osi/os/WIN32/osdThread.c'
49--- src/libCom/osi/os/WIN32/osdThread.c 2013-12-17 18:54:04 +0000
50+++ src/libCom/osi/os/WIN32/osdThread.c 2014-05-18 15:26:56 +0000
51@@ -1101,6 +1101,18 @@
52 return ( void * ) TlsGetValue ( pPvt->key );
53 }
54
55+/*
56+ * epicsThreadGetCPUs ()
57+ */
58+epicsShareFunc int epicsThreadGetCPUs ( void )
59+{
60+ SYSTEM_INFO sysinfo;
61+ GetSystemInfo(&sysinfo);
62+ if (sysinfo.dwNumberOfProcessors > 0)
63+ return sysinfo.dwNumberOfProcessors;
64+ return 1;
65+}
66+
67 #ifdef TEST_CODES
68 void testPriorityMapping ()
69 {
70
71=== modified file 'src/libCom/osi/os/posix/osdThread.c'
72--- src/libCom/osi/os/posix/osdThread.c 2012-09-20 19:55:32 +0000
73+++ src/libCom/osi/os/posix/osdThread.c 2014-05-18 15:26:56 +0000
74@@ -3,7 +3,7 @@
75 * National Laboratory.
76 * Copyright (c) 2002 The Regents of the University of California, as
77 * Operator of Los Alamos National Laboratory.
78-* Copyright (c) 2012 ITER Organization
79+* Copyright (c) 2013 ITER Organization.
80 * EPICS BASE is distributed subject to a Software License Agreement found
81 * in file LICENSE that is included with this distribution.
82 \*************************************************************************/
83@@ -873,3 +873,18 @@
84 return 1.0 / hz;
85 }
86
87+epicsShareFunc int epicsThreadGetCPUs(void)
88+{
89+ long ret;
90+#ifdef _SC_NPROCESSORS_ONLN
91+ ret = sysconf(_SC_NPROCESSORS_ONLN);
92+ if (ret > 0)
93+ return ret;
94+#endif
95+#ifdef _SC_NPROCESSORS_CONF
96+ ret = sysconf(_SC_NPROCESSORS_CONF);
97+ if (ret > 0)
98+ return ret;
99+#endif
100+ return 1;
101+}
102
103=== modified file 'src/libCom/osi/os/vxWorks/osdThread.c'
104--- src/libCom/osi/os/vxWorks/osdThread.c 2013-06-07 23:08:38 +0000
105+++ src/libCom/osi/os/vxWorks/osdThread.c 2014-05-18 15:26:56 +0000
106@@ -447,3 +447,8 @@
107 double HZ = sysClkRateGet ();
108 return 1.0 / HZ;
109 }
110+
111+epicsShareFunc int epicsThreadGetCPUs(void)
112+{
113+ return 1;
114+}
115
116=== modified file 'src/libCom/test/epicsThreadTest.cpp'
117--- src/libCom/test/epicsThreadTest.cpp 2006-11-09 22:38:41 +0000
118+++ src/libCom/test/epicsThreadTest.cpp 2014-05-18 15:26:56 +0000
119@@ -81,7 +81,11 @@
120
121 MAIN(epicsThreadTest)
122 {
123- testPlan(8);
124+ testPlan(9);
125+
126+ unsigned int ncpus = epicsThreadGetCPUs();
127+ testDiag("System has %u CPUs", ncpus);
128+ testOk1(ncpus > 0);
129
130 const int ntasks = 3;
131 myThread *myThreads[ntasks];

Subscribers

People subscribed via source and target branches

to all changes: