Giter Club home page Giter Club logo

Comments (3)

anrieff avatar anrieff commented on August 23, 2024

Hi!
Yes, VM hosts virtualize the results of the cpuid instruction to the point it doesn't look like a real CPU anymore. libcpuid detection can be (dis)trusted to varying degrees under a VM for that reason, since it may be not very obvious what they changed about cpuid's return results.

This particular error is caused by a VM which was allotted only one "processor", thus num_core=1, however the VM host didn't change num_smt, which on the real CPU is 2. Thus 1/2 = 0. On a "real" cpu such a bug could never happen.

For the usual computing tasks, the recommended approach is to use cpu_id_t::total_logical_cpus, which is obtained underneath through OS routines and should be always correct. In most cases you wouldn't care how many actual, real cores a CPU has - and whether it has HT. We just want to launch a computation on all possible compute units. On a 4-core HT CPU, that would be 8; in a VM on the same machine, with 1 "processor" allotted, that would be 1, and total_logical_cpus will be having the correct value in both cases.

That being said, I'll change the code line to something like data->num_cores = max(num_core / num_smt, 1);. It doesn't change anything on a real CPU, and would prevent the idiotic zero return under a VM.

from libcpuid.

alexey-milovidov avatar alexey-milovidov commented on August 23, 2024

Thanks for detailed explanation!

That being said, I'll change the code line to something like data->num_cores = max(num_core / num_smt, 1);. It doesn't change anything on a real CPU, and would prevent the idiotic zero return under a VM.

Seems fine.

from libcpuid.

anrieff avatar anrieff commented on August 23, 2024

Fixed in e0505af

from libcpuid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.