• Bug#1109782: unblock: 7zip/25.00+dfsg-1 (13/13)

    From Bastian Germann@21:1/5 to All on Wed Jul 23 19:40:02 2025
    [continued from previous message]

    + If the calling process contains threads in multiple groups,
    + the function returns zero for both affinity masks
    +
    + note: tested in Win10: GetProcessAffinityMask() doesn't return 0
    + in (processAffinityMask) and (systemAffinityMask) masks.
    + We need to test it in Win11: how to get mask==0 from GetProcessAffinityMask()?
    + */
    + if (!res)
    + {
    + processAffinityMask = 0;
    + systemAffinityMask = 0;
    + }
    + if (Groups.GroupSizes.Size() > 1 && Groups.NumThreadsTotal)
    + if (// !res ||
    + processAffinityMask == 0 || // to support case described in DOCs and for (!res) case
    + processAffinityMask == systemAffinityMask) // for default nonchanged affinity
    + {
    + // we set IsGroupMode only if processAffinity is default (not changed). + res = TRUE;
    + IsGroupMode = true;
    + }
    + return res;
    }


    +UInt32 CProcessAffinity::Load_and_GetNumberOfThreads()
    +{
    + if (Get())
    + {
    + const UInt32 numProcessors = GetNumProcessThreads();
    + if (numProcessors)
    + return numProcessors;
    + }
    + SYSTEM_INFO systemInfo;
    + GetSystemInfo(&systemInfo);
    + // the number of logical processors in the current group
    + return systemInfo.dwNumberOfProcessors;
    +}
    +
    UInt32 GetNumberOfProcessors()
    {
    // We need to know how many threads we can use.
    // By default the process is assigned to one group.
    - // So we get the number of logical processors (threads)
    - // assigned to current process in the current group.
    - // Group size can be smaller than total number logical processors, for exammple, 2x36
    -
    CProcessAffinity pa;
    -
    - if (pa.Get() && pa.processAffinityMask != 0)
    - return pa.GetNumProcessThreads();
    -
    - SYSTEM_INFO systemInfo;
    - GetSystemInfo(&systemInfo);
    - // the number of logical processors in the current group
    - return (UInt32)systemInfo.dwNumberOfProcessors;
    + return pa.Load_and_GetNumberOfThreads();
    }

    #else
    diff -Nru 7zip-24.09+dfsg/CPP/Windows/System.h 7zip-25.00+dfsg/CPP/Windows/System.h
    --- 7zip-24.09+dfsg/CPP/Windows/System.h 2024-10-02 10:00:00.000000000 +0200
    +++ 7zip-25.00+dfsg/CPP/Windows/System.h 2025-06-30 12:00:00.000000000 +0200
    @@ -9,6 +9,7 @@
    #endif

    #include "../Common/MyTypes.h"
    +#include "../Common/MyVector.h"
    #include "../Common/MyWindows.h"

    namespace NWindows {
    @@ -16,6 +17,34 @@

    #ifdef _WIN32

    +struct CCpuGroups
    +{
    + CRecordVector<UInt32> GroupSizes;
    + UInt32 NumThreadsTotal; // sum of threads in all groups
    + // bool Is_Win11_Groups; // useless
    +
    + void Get_GroupSize_Min_Max(UInt32 &minSize, UInt32 &maxSize) const
    + {
    + unsigned num = GroupSizes.Size();
    + UInt32 minSize2 = 0, maxSize2 = 0;
    + if (num)
    + {
    + minSize2 = (UInt32)0 - 1;
    + do
    + {
    + const UInt32 v = GroupSizes[--num];
    + if (minSize2 > v) minSize2 = v;
    + if (maxSize2 < v) maxSize2 = v;
    + }
    + while (num);
    + }
    + minSize = minSize2;
    + maxSize = maxSize2;
    + }
    + bool Load();
    + CCpuGroups(): NumThreadsT