I'm trying to compile Boost 1.49.0 for WinRT. I've got it down to one method: GetSystemInfo(), which is used in boost::thread::hardware_concurrency() to obtain the number of logical processors on the system.
I haven't found any replacement in WinRT yet.
Is there an alternative method I could use?
You can call the Windows API function GetNativeSystemInfo, which is permitted in Metro style apps.
There doesn't seem to be a simple way to get this information in WinRT. If you just want to know the processor architecture then you can use Windows.System.ProcessorArchitecture but this will not tell you how many logical CPUs are available. Windows.System.Threading doesn't tell you this information either.
To get information about the physical CPU I've found this question on the MSDN forum which suggests that we can use DeviceEnumeration to get to this information. By using the GUID for GUID_DEVICE_PROCESSOR ({97FADB10-4E33-40AE-359C-8BEF029DBDD0}) you can enumerate over all processors.
In Javascript this should look something like this - for a C++ example see the Device Enumeration example on MSDN:
Windows.Devices.Enumeration.DeviceInformation.findAllAsync('"System.Devices.InterfaceClassGuid:="{97FADB10-4E33-40AE-359C-8BEF029DBDD0}""')
.then(function (info) {
for (var i = 0; i < info.length; i++) {
var device = info[i];
}
});
On my machine this gives me all sorts of devices, sound card, PCI and USB processors so I'm not sure if there is a better way to just get the CPU but I did get the info what CPU I have
"Intel(R) Core(TM) i7 CPU Q 740 # 1.73GHz"
Unfortunately this info doesn't seem to include a simple flag that tells you the number of CPUs and therefore I think it would be difficult to get to a number of logical CPUs. I suggest you ask on the MSDN forum. They are usually quite responsive.
System.Environment.ProcessorCount should give you the number of cores.
Related
In the case of CPUs, the (linux specific) sys calls getcpu() or sched_getcpu() can be used inside a program to obtain the ID of the core executing them. For example, in the case of a 4 processors system, the logical index returned by the mentionned calls makes it possible to deduce which one of the 4 CPUs is being used (let's say every CPU contains 10 cores, therefore if sched_getcpu() returns 20, that means the CPU #2 is being used since the core number 20 is in the 3rd CPU).
How can I achieve a similar thing in the case of GPUs? Is there a way to find which one is being used in real time from inside an application?
C++ has no concept of a GPU. You got a great comment pointing you to the right direction of getting some GPU info using OpenGL, I'm sure there are other cross platform libraries as well.
Take a look at the source code of neofetch which is a command-line system info tool which, among other things, gets your GPU(s). It uses a bunch of different methods to get the GPU on the current system, some of which may help point you to the right direction. For example, for linux systems it gets the gpu info using lspci -mm:
echo $(lspci -mm | awk -F '\"|\" \"|\\(' \
'/"Display|"3D|"VGA/ {
a[$0] = $1 " " $3 " " ($(NF-1) ~ /^$|^Device [[:xdigit:]]+$/ ? $4 : $(NF-1))
}
END { for (i in a) {
if (!seen[a[i]]++) {
sub("^[^ ]+ ", "", a[i]);
print a[i]
}
}}')
which returns NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] for my system. But this is not cross platform. If you wanted to do it yourself you would thus have to either:
implement a way for every system your application will run on
lose cross-platform ability
Or simply use OpenGL as mentioned above.
It depends on the API you are using to access the GPU. Under vulkan, the capability to query the available devices is provided in the API itself. e.g.
vkEnumeratePhysicalDevices //< use to iterate over devices
vkGetPhysicalDeviceProperties //< use to determine make/model
vkGetPhysicalDeviceFeatures //< use to determine the capabilities
Under OpenGL, this is a little harder, because the API doesn't really provide a nice robust way of iterating over connected GPU's (this is very much left to the underlying OS). Aside from calling glGetString with GL_VENDOR, and/or GL_RENDERER, after the context has been created, that's about all you have got.
With graphics API's in general, you will typically choose the device to use up front, and then forget about it. (i.e. you know which GPU is in use, because it's the one you requested)
So for example, on windows you'd use the WIn32 API call EnumDisplayDevices to iterate over a bunch of DISPLAY_DEVICE structures, which give you a breakdown of the GPU devices. If you then want to query the device capabilities, you'd need to initialise an OpenGL context (with the correct device), and make multiple calls to glGetIntegerv to query the actual capabilities.
Sadly, on linux this is a little trickier. Iterating the display devices is pretty much going to depend on the underlying API you are using to initialise the GPU (e.g. GLX, SDL, Qt, etc).
So for example, in SDL you would iterate over the available devices using SDL_GetRenderDriverInfo, before passing your preferred device index to SDL_CreateRenderer at app startup.
I want to filter some data (100s of MB to a few GBs). The user can change the filters so I have to re-filter the data frequently.
The code is rather simple:
std::vector<Event*> filteredEvents;
for (size_t i = 0; i < events.size(); i++){
const auto ev = events[i];
for (const auto& filter : filters) {
if (filter->evaluate(ev)) {
filteredEvents->push_back(ev);
break;
}
}
if (i % 512 == 0) {
updateProgress(i);
}
}
I now want to add another filter. I can do that either in a way that uses more CPU or that uses more memory. To decide between the two I would like to know what the bottleneck of the above loop is.
How do I profile the code to decide if the bottleneck is the cpu or the memory?
In case it matters, the project is written in Qt and I use Qt Creator as the idea. The platform is Windows. I am currently using Very Sleepy to profile my code.
Intel vTune is a free graphical tool available for all of Windows and Linux and macOS. If you want something easy to set up, straightforward to read, and you're using Intel CPU, I'd say vTune is a good choice. It can automatically give you suggestions on where your bottleneck is (core vs memory).
Under the hood I believe Intel vTune is collecting a bunch of PMU (performance monitoring unit) counter values, LBR, stack information etc. On Linux, you are more than welcome to utilize the Linux Perf tool and collect performance stats for yourself. For example, using perf record + perf report in tandem tells you the hotspot of your application. But if you're concerned about other metrics, for example cache miss behavior, you'll have to explicitly tell perf what performance counter to collect. perf mem is able to address some of that need. But afterall, Linux Perf is a lot more "hard core" than the graphical Intel vTune, you better know what counter values to look for if you want to make good use of Linux Perf - sometimes one counter will directly give you the metric you want to collect, other times you have to do some computation on several counter values to get your desired metric. Use perf list to appreciate how detailed it can profile your machine and system's performance.
I can't get the CPU ID or motherboard serial number in all operating system (cross platform Qt)
On Windows I'm using WMI and on Mac another. I want use a cross-platform library.
Although Qt detects at runtime the CPU feature set (cf. src/corelib/tools/qsimd.cpp), it does not export any function to access that (nor any other CPUID information). Write your small piece of assembly code to gather that information. - source
You will have to write some platform dependent code to retrieve this information.
For the CPU id you should probably look into the function __cpuid() for Windows and this answer can help you out on getting it for Linux.
Doing this you might want to consider reading up on motherboard serial numbers as not all of them provide this information at the same place (most do not provide it at all).
You can execute this command :
"wmic cpu get ProcessorId"
Qt 5.11 introduced this function: QSysInfo::machineUniqueId
I want to find the interface supplied by windows to change the CPU frequency and core voltage.
Thanks!
you can change frequency by using
PowerWriteACValueIndex()/PowerWriteDCValueIndex()
when setting the same index value for both
GUID_PROCESSOR_THROTTLE_MAXIMUM | GUID_PROCESSOR_THROTTLE_MINIMUM
all the GUID description could be found in winnt.h
you cannot change CPU voltage by WINAPI. you should use the privileged commands to write to specific MSRs (see AMD/Intel docs) via system kernel driver.
you cannot change Intel CPU voltage AT ALL since Nehalem micro-architecture. Intel officially does not supply MSRs to write voltage values (VIDs) by software.
From Windows Native Processor Performance Control(document link)
Parameters to P-state policy
Several parameters to Windows processor performance state controls are configurable via registry keys. These keys are provided with the intent that OEMs and system designers may tune the performance of Windows processor power management features to best suit specific platform designs, and allow adjustment to help achieve maximum battery life and realize the best system performance.
And you have to restart to have the changes take effect.
Microsoft Windows does not have an API for overclocking / underclocking a CPU. You would have to roll your own using your assembler skills.
I can do no more than point you in the right direction. I think through Windows Management Instrumentation (WMI) you can get at a COM interface that allows modification of some sub-systems.
Hopefully that vague bit of information will set you on the right path. :-)
I want to be able to get the current % CPU usage in a C++ program running under Wince.
I found this link that states where the source code is but I cannot find it in my platform builder installation - I expect this is because it isn't the Windows Automotive platform.
Does anyone know where I can find this source code or (even better) know how I can get this information directly? i.e. what DLL / function calls to make etc.
Since GetProcessTimes doesn't exist in CE, you have to calculate this.
You have to start with the toolhelp APIs to enumerate the processes and the threads in the processes. You then call GetThreadTimes for each thread and add all that up.
Bear in mind that the act of calculating this info will affect the CPU utilization.
I have found that GetIdleTime (or CeGetIdleTimeEx on WEC7 or newer) works well for calculating system-wide processor usage. Sample code for calculating processor idle time percentage is shown on GetIdleTime MSDN page. Obviously, processor utilization percentage can then be calculated by subtracting the idle time percentage from 100.
The MSDN page does warn that support for GetIdleTime is dependent on OAL implementation.
Note that when using the toolhelp APIs to calculate the CPU usage, you need to take two measurements, then calculate the difference. when doing so, you won't know how much CPU any threads that were terminated before the second sample took.
So, applications that often create short-lived threads will not be represented properly in your result.
You can look into Remote Task Monitor. It will let you get the current % CPU usage of your process (or thread), exactly what you are looking for. It also is very light weight, does not impact your device much.