VirtualBox

Changeset 26599 in vbox


Ignore:
Timestamp:
Feb 17, 2010 10:33:37 AM (15 years ago)
Author:
vboxsync
Message:

CPU hotplug/Additions: Fix hot-add event. The cpu directory might not be immediately created when the service gets the notification. Iterate over the directories a few times

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceCpuHotPlug.cpp

    r26595 r26599  
    154154#ifdef RT_OS_LINUX
    155155    /*
    156      * The topology directory is not available until the CPU is online. So we just iterate over all directories
     156     * The topology directory (containing the physical and core id properties)
     157     * is not available until the CPU is online. So we just iterate over all directories
    157158     * and enable every CPU which is not online already.
     159     * Because the directory might not be available immediately we try a few times.
     160     *
     161     * @todo: Maybe use udev to monitor hot-add events from the kernel
    158162     */
    159     /** @todo Maybe use udev to monitor events from the kernel */
    160     PRTDIR pDirDevices = NULL;
    161     int rc = RTDirOpen(&pDirDevices, SYSFS_CPU_PATH);  /*could use RTDirOpenFiltered*/
    162     if (RT_SUCCESS(rc))
     163    bool fCpuOnline = false;
     164    unsigned cTries = 5;
     165
     166    do
    163167    {
    164         RTDIRENTRY DirFolderContent;
    165         while (RT_SUCCESS(RTDirRead(pDirDevices, &DirFolderContent, NULL))) /* Assumption that szName has always enough space */
    166         {
    167 /** @todo r-bird: This code is bringing all CPUs online; the idCpuCore and
    168  *        idCpuPackage parameters are unused!   
    169  *        aeichner: These files are not available at this point unfortunately. (see comment above)
    170  */
    171             /*
    172              * Check if this is a CPU object.
    173              * cpu0 is excluded because it is not possible to change the state
    174              * of the first CPU on Linux (it doesn't even have an online file)
    175              * and cpuidle is no CPU device. Prevents error messages later.
    176              */
    177             if(   !strncmp(DirFolderContent.szName, "cpu", 3)
    178                 && strncmp(DirFolderContent.szName, "cpu0", 4)
    179                 && strncmp(DirFolderContent.szName, "cpuidle", 7))
     168        PRTDIR pDirDevices = NULL;
     169        int rc = RTDirOpen(&pDirDevices, SYSFS_CPU_PATH);
     170        if (RT_SUCCESS(rc))
     171        {
     172            RTDIRENTRY DirFolderContent;
     173            while (RT_SUCCESS(RTDirRead(pDirDevices, &DirFolderContent, NULL))) /* Assumption that szName has always enough space */
    180174            {
    181                 /* Get the sysdev */
    182                 RTFILE hFileCpuOnline = NIL_RTFILE;
    183                 rc = RTFileOpenF(&hFileCpuOnline, RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE,
    184                                  "%s/%s/online", SYSFS_CPU_PATH, DirFolderContent.szName);
    185                 if (RT_SUCCESS(rc))
     175                /** @todo r-bird: This code is bringing all CPUs online; the idCpuCore and
     176                 *        idCpuPackage parameters are unused!   
     177                 *        aeichner: These files are not available at this point unfortunately. (see comment above)
     178                 */
     179                /*
     180                 * Check if this is a CPU object.
     181                 * cpu0 is excluded because it is not possible to change the state
     182                 * of the first CPU on Linux (it doesn't even have an online file)
     183                 * and cpuidle is no CPU device. Prevents error messages later.
     184                 */
     185                if(   !strncmp(DirFolderContent.szName, "cpu", 3)
     186                    && strncmp(DirFolderContent.szName, "cpu0", 4)
     187                    && strncmp(DirFolderContent.szName, "cpuidle", 7))
    186188                {
    187                     /* Write a 1 to online the CPU */
    188                     rc = RTFileWrite(hFileCpuOnline, "1", 1, NULL);
    189                     RTFileClose(hFileCpuOnline);
     189                    /* Get the sysdev */
     190                    RTFILE hFileCpuOnline = NIL_RTFILE;
     191
     192                    rc = RTFileOpenF(&hFileCpuOnline, RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE,
     193                                     "%s/%s/online", SYSFS_CPU_PATH, DirFolderContent.szName);
    190194                    if (RT_SUCCESS(rc))
    191195                    {
    192                         VBoxServiceVerbose(1, "CpuHotPlug: CPU %u/%u was brought online\n", idCpuPackage, idCpuCore);
    193                         break;
     196                        /* Write a 1 to online the CPU */
     197                        rc = RTFileWrite(hFileCpuOnline, "1", 1, NULL);
     198                        RTFileClose(hFileCpuOnline);
     199                        if (RT_SUCCESS(rc))
     200                        {
     201                            VBoxServiceVerbose(1, "CpuHotPlug: CPU %u/%u was brought online\n", idCpuPackage, idCpuCore);
     202                            fCpuOnline = true;
     203                            break;
     204                        }
     205                        /* Error means CPU not present or online already  */
    194206                    }
    195                     /* Error means CPU not present or online already  */
     207                    else
     208                        VBoxServiceError("CpuHotPlug: Failed to open \"%s/%s/online\" rc=%Rrc\n",
     209                                         SYSFS_CPU_PATH, DirFolderContent.szName, rc);
    196210                }
    197                 else
    198                     VBoxServiceError("CpuHotPlug: Failed to open \"%s/%s/online\" rc=%Rrc\n",
    199                                      SYSFS_CPU_PATH, DirFolderContent.szName, rc);
    200211            }
    201212        }
    202     }
    203     else
    204         VBoxServiceError("CpuHotPlug: Failed to open path %s rc=%Rrc\n", SYSFS_CPU_PATH, rc);
     213        else
     214            VBoxServiceError("CpuHotPlug: Failed to open path %s rc=%Rrc\n", SYSFS_CPU_PATH, rc);
     215
     216        /* Sleep a bit */
     217        if (!fCpuOnline)
     218            RTThreadSleep(10);
     219
     220    } while (   !fCpuOnline
     221             && cTries-- > 0);
    205222#else
    206223# error "Port me"
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