[M3devel] Thread.HardwareConcurrency()?
Jay K
jayk123 at hotmail.com
Tue Jul 4 09:27:21 CEST 2017
Clearing out more backlog...
I suggest, for example, the cm3 compiler should use
a thread per "processor" for the backend.
I acknowledge that "processor" isn't well defined, such as with Intel
hyperthreading and in general with various resources (registers, integer ALU,
floating point ALU, branch predictor memory, cache) not being equally duplicated.
I acknowledge that hogging all the CPU is deleterious to interactive
performance, or overall system performance if anything else is running.
Adapting to overall system load and being good citizen is quite difficult
unless you are the semi-omniscient operating system kernel.
I believe C++11 exposes this notion and Boost did before it.
(C++11 finally acknowledged the existance of threads and has
a memory model and library for them, 20 years late)
I propose that we can freely integrate Boost code into our runtime.
That its license is close in spirit to ours.
edit m3-libs/m3core/src/thread/Common/BoostThread.cpp
#ifndef _WIN32
// Copyright (C) 2001-2003
// William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifdef __GLIBC__
#include <sys/sysinfo.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#else // if defined BOOST_HAS_UNISTD_H
#include <unistd.h>
#endif
#endif
extern "C"
unsigned m3_thread_hardware_concurrency()
{
#if defined(PTW32_VERSION) || defined(__hpux)
return pthread_num_processors_np();
#elif defined(__APPLE__) || defined(__FreeBSD__)
int count;
size_t size = sizeof(count);
return sysctlbyname("hw.ncpu", &count, &size, NULL, 0) ? 0 : count;
#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
int const count = sysconf(_SC_NPROCESSORS_ONLN);
return (count > 0) ? count : 0;
#elif defined(__GLIBC__)
return get_nprocs();
#else
return 0;
#endif
}
#else
#include <windows.h>
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright 2007 Anthony Williams
// (C) Copyright 2007 David Deakins
// (C) Copyright 2011-2013 Vicente J. Botet Escriba
extern "C"
unsigned m3_m3_thread_hardware_concurrency()
{
SYSTEMINFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
#endif
and then something in Thread.i3.
<* external m3_thread_hardware_concurrent *>
PROCEDURE Thread.HardwareConcurrency(): INTEGER;
?
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20170704/47df7022/attachment-0001.html>
More information about the M3devel
mailing list