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

Proposed by Ralph Lange
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 Approve
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.
Revision history for this message
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

Revision history for this message
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
12412. By Ralph Lange

.bzrignore: add QtCreator project files

12413. By Ralph Lange

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

Revision history for this message
Ralph Lange (ralph-lange) wrote :

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

Revision history for this message
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
=== modified file '.bzrignore'
--- .bzrignore 2012-06-22 23:16:26 +0000
+++ .bzrignore 2014-05-18 15:26:56 +0000
@@ -6,3 +6,4 @@
6./include6./include
7./templates7./templates
8**/O.*8**/O.*
9./QtC-*
910
=== modified file 'src/libCom/osi/epicsThread.h'
--- src/libCom/osi/epicsThread.h 2012-07-06 21:33:10 +0000
+++ src/libCom/osi/epicsThread.h 2014-05-18 15:26:56 +0000
@@ -3,7 +3,7 @@
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* Copyright (c) 2012 ITER Organization6* Copyright (c) 2013 ITER Organization.
7* EPICS BASE is distributed subject to a Software License Agreement found7* EPICS BASE is distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 8* in file LICENSE that is included with this distribution.
9\*************************************************************************/9\*************************************************************************/
@@ -85,6 +85,7 @@
85epicsShareFunc double epicsShareAPI epicsThreadSleepQuantum(void);85epicsShareFunc double epicsShareAPI epicsThreadSleepQuantum(void);
86epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetIdSelf(void);86epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetIdSelf(void);
87epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetId(const char *name);87epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetId(const char *name);
88epicsShareFunc int epicsThreadGetCPUs(void);
8889
89epicsShareFunc const char * epicsShareAPI epicsThreadGetNameSelf(void);90epicsShareFunc const char * epicsShareAPI epicsThreadGetNameSelf(void);
9091
9192
=== modified file 'src/libCom/osi/os/RTEMS/osdThread.c'
--- src/libCom/osi/os/RTEMS/osdThread.c 2012-07-31 19:04:38 +0000
+++ src/libCom/osi/os/RTEMS/osdThread.c 2014-05-18 15:26:56 +0000
@@ -718,3 +718,12 @@
718718
719 return 1.0 / rtemsTicksPerSecond_double;719 return 1.0 / rtemsTicksPerSecond_double;
720}720}
721
722epicsShareFunc int epicsThreadGetCPUs(void)
723{
724#if defined(RTEMS_SMP)
725 return rtems_smp_get_number_of_processors();
726#else
727 return 1;
728#endif
729}
721730
=== modified file 'src/libCom/osi/os/WIN32/osdThread.c'
--- src/libCom/osi/os/WIN32/osdThread.c 2013-12-17 18:54:04 +0000
+++ src/libCom/osi/os/WIN32/osdThread.c 2014-05-18 15:26:56 +0000
@@ -1101,6 +1101,18 @@
1101 return ( void * ) TlsGetValue ( pPvt->key );1101 return ( void * ) TlsGetValue ( pPvt->key );
1102}1102}
11031103
1104/*
1105 * epicsThreadGetCPUs ()
1106 */
1107epicsShareFunc int epicsThreadGetCPUs ( void )
1108{
1109 SYSTEM_INFO sysinfo;
1110 GetSystemInfo(&sysinfo);
1111 if (sysinfo.dwNumberOfProcessors > 0)
1112 return sysinfo.dwNumberOfProcessors;
1113 return 1;
1114}
1115
1104#ifdef TEST_CODES1116#ifdef TEST_CODES
1105void testPriorityMapping ()1117void testPriorityMapping ()
1106{1118{
11071119
=== modified file 'src/libCom/osi/os/posix/osdThread.c'
--- src/libCom/osi/os/posix/osdThread.c 2012-09-20 19:55:32 +0000
+++ src/libCom/osi/os/posix/osdThread.c 2014-05-18 15:26:56 +0000
@@ -3,7 +3,7 @@
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* Copyright (c) 2012 ITER Organization6* Copyright (c) 2013 ITER Organization.
7* EPICS BASE is distributed subject to a Software License Agreement found7* EPICS BASE is distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 8* in file LICENSE that is included with this distribution.
9\*************************************************************************/9\*************************************************************************/
@@ -873,3 +873,18 @@
873 return 1.0 / hz;873 return 1.0 / hz;
874}874}
875875
876epicsShareFunc int epicsThreadGetCPUs(void)
877{
878 long ret;
879#ifdef _SC_NPROCESSORS_ONLN
880 ret = sysconf(_SC_NPROCESSORS_ONLN);
881 if (ret > 0)
882 return ret;
883#endif
884#ifdef _SC_NPROCESSORS_CONF
885 ret = sysconf(_SC_NPROCESSORS_CONF);
886 if (ret > 0)
887 return ret;
888#endif
889 return 1;
890}
876891
=== modified file 'src/libCom/osi/os/vxWorks/osdThread.c'
--- src/libCom/osi/os/vxWorks/osdThread.c 2013-06-07 23:08:38 +0000
+++ src/libCom/osi/os/vxWorks/osdThread.c 2014-05-18 15:26:56 +0000
@@ -447,3 +447,8 @@
447 double HZ = sysClkRateGet ();447 double HZ = sysClkRateGet ();
448 return 1.0 / HZ;448 return 1.0 / HZ;
449}449}
450
451epicsShareFunc int epicsThreadGetCPUs(void)
452{
453 return 1;
454}
450455
=== modified file 'src/libCom/test/epicsThreadTest.cpp'
--- src/libCom/test/epicsThreadTest.cpp 2006-11-09 22:38:41 +0000
+++ src/libCom/test/epicsThreadTest.cpp 2014-05-18 15:26:56 +0000
@@ -81,7 +81,11 @@
8181
82MAIN(epicsThreadTest)82MAIN(epicsThreadTest)
83{83{
84 testPlan(8);84 testPlan(9);
85
86 unsigned int ncpus = epicsThreadGetCPUs();
87 testDiag("System has %u CPUs", ncpus);
88 testOk1(ncpus > 0);
8589
86 const int ntasks = 3;90 const int ntasks = 3;
87 myThread *myThreads[ntasks];91 myThread *myThreads[ntasks];

Subscribers

People subscribed via source and target branches

to all changes: