VirtualBox

Changeset 83326 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 19, 2020 12:16:12 PM (5 years ago)
Author:
vboxsync
Message:

IPRT/r0drv/mp-r0drv-linux.c: Use version checks for linux/cpumask.h stuff rather than assuming that everything in it will remain macros forever (num_online_cpus isn't anymore). Fixed possible bug in RTMpGetCount where it wouldn't handle CPU hotplugging right.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/linux/mp-r0drv-linux.c

    r82968 r83326  
    3939#include "r0drv/mp-r0drv.h"
    4040
    41 #ifdef nr_cpumask_bits
    42 # define VBOX_NR_CPUMASK_BITS   nr_cpumask_bits
     41
     42/*********************************************************************************************************************************
     43*   Defined Constants And Macros                                                                                                 *
     44*********************************************************************************************************************************/
     45#if defined(nr_cpumask_bits) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
     46# define VBOX_NR_CPUMASK_BITS   (nr_cpumask_bits)   /* same as nr_cpu_ids */
    4347#else
    44 # define VBOX_NR_CPUMASK_BITS   NR_CPUS
     48# define VBOX_NR_CPUMASK_BITS   (NR_CPUS)
    4549#endif
    4650
     
    7680RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
    7781{
    78     return iCpu < VBOX_NR_CPUMASK_BITS ? (RTCPUID)iCpu : NIL_RTCPUID;
     82    return (unsigned)iCpu < VBOX_NR_CPUMASK_BITS ? (RTCPUID)iCpu : NIL_RTCPUID;
    7983}
    8084RT_EXPORT_SYMBOL(RTMpCpuIdFromSetIndex);
     
    8387RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
    8488{
    85     return VBOX_NR_CPUMASK_BITS - 1; //???
     89    return VBOX_NR_CPUMASK_BITS - 1;
    8690}
    8791RT_EXPORT_SYMBOL(RTMpGetMaxCpuId);
     
    9195{
    9296#if defined(CONFIG_SMP)
    93     if (RT_UNLIKELY(idCpu >= VBOX_NR_CPUMASK_BITS))
    94         return false;
    95 
    96 # if defined(cpu_possible)
    97     return cpu_possible(idCpu);
     97# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2) || defined(cpu_possible)
     98    return idCpu < VBOX_NR_CPUMASK_BITS && cpu_possible(idCpu);
    9899# else /* < 2.5.29 */
    99     return idCpu < (RTCPUID)smp_num_cpus;
     100    return idCpu < (RTCPUID)(smp_num_cpus);
    100101# endif
    101102#else
     
    125126{
    126127#ifdef CONFIG_SMP
    127 # if defined(CONFIG_HOTPLUG_CPU) /* introduced & uses cpu_present */
    128     return num_present_cpus();
    129 # elif defined(num_possible_cpus)
     128# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 4) || defined(num_possible_cpus)
    130129    return num_possible_cpus();
    131130# elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
     
    146145{
    147146#ifdef CONFIG_SMP
    148     if (RT_UNLIKELY(idCpu >= VBOX_NR_CPUMASK_BITS))
    149         return false;
    150 # ifdef cpu_online
    151     return cpu_online(idCpu);
     147# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) || defined(cpu_online)
     148    return idCpu < VBOX_NR_CPUMASK_BITS && cpu_online(idCpu);
    152149# else /* 2.4: */
    153     return cpu_online_map & RT_BIT_64(idCpu);
     150    return idCpu < VBOX_NR_CPUMASK_BITS && cpu_online_map & RT_BIT_64(idCpu);
    154151# endif
    155152#else
     
    184181{
    185182#ifdef CONFIG_SMP
    186 # if defined(num_online_cpus)
     183# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) || defined(num_online_cpus)
    187184    return num_online_cpus();
    188185# else
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette