Potential solution for SMT disabled cases.
_SC_NPROCESSORS_CONF returns offline cores too which will cause sched_setaffinity to fail.
_SC_NPROCESSORS_ONLN is a fix but that apparently also ignores sleeping cores, which I believe is somewhat common on power saving modes in laptops. Somewhat unconfirmed as the documentation is not clear if sleeping cores are actually considered offline, however, there is a thread of Mozilla bugtracker about this not not counting those cores on some ARM setup.
If this does not suffice, the case needs to be handled in the affinity setting code.