Changeset 3313 for trunk/src/kmk/w32


Ignore:
Timestamp:
Mar 16, 2020, 3:31:38 AM (5 years ago)
Author:
bird
Message:

kmk,kWorker: Assign processor groups to kWorker processes. Added --special-env hack for having a mspdbsrv.exe instance per processor group (using _MSPDBSRV_ENDPOINT_). This was complicated by PCH requiring to share .pdb file and therefore mspdbsrv.exe instance, requiring a mspdb100.dll re-init hack to disconnect kWorker from the previous mspdbsrv when switching. fun.

Location:
trunk/src/kmk/w32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/w32/winchildren.c

    r3224 r3313  
    334334/** Pointer to childcare workers. */
    335335static PWINCHILDCAREWORKER *g_papChildCareworkers = NULL;
    336 /** The group index for the worker allocator.
    337  * This is ever increasing and must be modded by g_cProcessorGroups. */
    338 static unsigned             g_idxProcessorGroupAllocator = 0;
    339 /** The processor in group index for the worker allocator. */
    340 static unsigned             g_idxProcessorInGroupAllocator = 0;
     336/** The processor group allocator state. */
     337static MKWINCHILDCPUGROUPALLOCSTATE g_ProcessorGroupAllocator;
    341338/** Number of processor groups in the system.   */
    342339static unsigned             g_cProcessorGroups = 1;
     
    468465                pacProcessorsInGroup[iGroup] = g_pfnGetActiveProcessorCount(iGroup);
    469466
    470             /* We shift the starting group with the make nesting level as part of
    471                our very simple distribution strategy. */
    472             g_idxProcessorGroupAllocator = makelevel;
     467            MkWinChildInitCpuGroupAllocator(&g_ProcessorGroupAllocator);
    473468        }
    474469        else
     
    26352630
    26362631/**
     2632 * Initializes the processor group allocator.
     2633 *
     2634 * @param   pState              The allocator to initialize.
     2635 */
     2636void MkWinChildInitCpuGroupAllocator(PMKWINCHILDCPUGROUPALLOCSTATE pState)
     2637{
     2638    /* We shift the starting group with the make nesting level as part of
     2639       our very simple distribution strategy. */
     2640    pState->idxGroup = makelevel;
     2641    pState->idxProcessorInGroup = 0;
     2642}
     2643
     2644/**
     2645 * Allocate CPU group for the next child process.
     2646 *
     2647 * @returns CPU group.
     2648 * @param   pState              The allocator state.  Must be initialized by
     2649 *                              MkWinChildInitCpuGroupAllocator().
     2650 */
     2651unsigned int MkWinChildAllocateCpuGroup(PMKWINCHILDCPUGROUPALLOCSTATE pState)
     2652{
     2653    unsigned int iGroup = 0;
     2654    if (g_cProcessorGroups > 1)
     2655    {
     2656        unsigned int cMaxInGroup;
     2657        unsigned int cInGroup;
     2658
     2659        iGroup = pState->idxGroup % g_cProcessorGroups;
     2660
     2661        /* Advance.  We employ a very simple strategy that does 50% in
     2662           each group for each group cycle.  Odd processor counts are
     2663           caught in odd group cycles.  The init function selects the
     2664           starting group based on make nesting level to avoid stressing
     2665           out the first group. */
     2666        cInGroup = ++pState->idxProcessorInGroup;
     2667        cMaxInGroup = g_pacProcessorsInGroup[iGroup];
     2668        if (   !(cMaxInGroup & 1)
     2669            || !((pState->idxGroup / g_cProcessorGroups) & 1))
     2670            cMaxInGroup /= 2;
     2671        else
     2672            cMaxInGroup = cMaxInGroup / 2 + 1;
     2673        if (cInGroup >= cMaxInGroup)
     2674        {
     2675            pState->idxProcessorInGroup = 0;
     2676            pState->idxGroup++;
     2677        }
     2678    }
     2679    return iGroup;
     2680}
     2681
     2682/**
    26372683 * Creates another childcare worker.
    26382684 *
     
    26542700            {
    26552701                /* Before we start the thread, assign it to a processor group. */
    2656                 if (g_cProcessorGroups > 1)
    2657                 {
    2658                     unsigned int cMaxInGroup;
    2659                     unsigned int cInGroup;
    2660                     unsigned int iGroup = g_idxProcessorGroupAllocator % g_cProcessorGroups;
    2661                     pWorker->iProcessorGroup = iGroup;
    2662 
    2663                     /* Advance.  We employ a very simple strategy that does 50% in
    2664                        each group for each group cycle.  Odd processor counts are
    2665                        caught in odd group cycles.  The init function selects the
    2666                        starting group based on make nesting level to avoid stressing
    2667                        out the first group. */
    2668                     cInGroup = ++g_idxProcessorInGroupAllocator;
    2669                     cMaxInGroup = g_pacProcessorsInGroup[iGroup];
    2670                     if (   !(cMaxInGroup & 1)
    2671                         || !((g_idxProcessorGroupAllocator / g_cProcessorGroups) & 1))
    2672                         cMaxInGroup /= 2;
    2673                     else
    2674                         cMaxInGroup = cMaxInGroup / 2 + 1;
    2675                     if (cInGroup >= cMaxInGroup)
    2676                     {
    2677                         g_idxProcessorInGroupAllocator = 0;
    2678                         g_idxProcessorGroupAllocator++;
    2679                     }
    2680                 }
     2702                pWorker->iProcessorGroup = MkWinChildAllocateCpuGroup(&g_ProcessorGroupAllocator);
    26812703
    26822704                /* Try start the thread. */
     
    34143436 * that completed children is the typical source of these tokens (esp. for kmk).
    34153437 *
    3416  * @returns Zero if completed children, event handle if waiting is required.
     3438 * @returns Zero if no active children, event handle if waiting is required.
    34173439 */
    34183440intptr_t MkWinChildGetCompleteEventHandle(void)
  • trunk/src/kmk/w32/winchildren.h

    r3200 r3313  
    2626#ifndef INCLUDED_WINCHILDREN_H
    2727#define INCLUDED_WINCHILDREN_H
     28
     29/** Child processor group allocator state. */
     30typedef struct MKWINCHILDCPUGROUPALLOCSTATE
     31{
     32    /** The group index for the worker allocator.
     33     * This is ever increasing and must be modded by g_cProcessorGroups. */
     34    unsigned int    idxGroup;
     35    /** The processor in group index for the worker allocator. */
     36    unsigned int    idxProcessorInGroup;
     37} MKWINCHILDCPUGROUPALLOCSTATE;
     38/** Pointer to a CPU group allocator state.   */
     39typedef MKWINCHILDCPUGROUPALLOCSTATE *PMKWINCHILDCPUGROUPALLOCSTATE;
    2840
    2941#ifdef DECLARE_HANDLE
     
    6880int     MkWinChildCreate(char **papszArgs, char **papszEnv, const char *pszShell, struct child *pMkChild, pid_t *pPid);
    6981int     MkWinChildCreateWithStdOutPipe(char **papszArgs, char **papszEnv, int fdErr, pid_t *pPid, int *pfdReadPipe);
     82void    MkWinChildInitCpuGroupAllocator(PMKWINCHILDCPUGROUPALLOCSTATE pState);
     83unsigned int MkWinChildAllocateCpuGroup(PMKWINCHILDCPUGROUPALLOCSTATE pState);
     84
    7085#ifdef KMK
    7186struct KMKBUILTINENTRY;
     
    86101                                   char **papszEnvVars, const char *pszCwd, BOOL pafReplace[3], HANDLE pahReplace[3]);
    87102# endif
    88 #endif
     103#endif /* KMK */
    89104int     MkWinChildKill(pid_t pid, int iSignal, struct child *pMkChild);
    90105int     MkWinChildWait(int fBlock, pid_t *pPid, int *piExitCode, int *piSignal, int *pfCoreDumped, struct child **ppMkChild);
Note: See TracChangeset for help on using the changeset viewer.