Skip to content
Prev Previous commit
Next Next commit
CHECK_CACHE_SIZE -> UPDATE_CACHE_SIZE_AND_LEVEL
  • Loading branch information
kunalspathak committed Jun 21, 2022
commit 5671866ea2e8253cb6ce63c5d6717b4049f426c0
12 changes: 6 additions & 6 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ bool ReadMemoryValueFromFile(const char* filename, uint64_t* val)
return result;
}

#define CHECK_CACHE_SIZE(CACHE_LEVEL) if (size > cacheSize) { cacheSize = size; cacheLevel = CACHE_LEVEL; }
#define UPDATE_CACHE_SIZE_AND_LEVEL(CACHE_LEVEL) if (size > cacheSize) { cacheSize = size; cacheLevel = CACHE_LEVEL; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nit - please feel free to do that later if you want to get this in before today's snap for preview 6.
Looking at the usages of this macro, I have realized it would be great to make the size a parameter of the macro too. From the usage sites, it is not obvious where it gets the size from (I have to read the macro definition to figure it out).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do it in follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


static size_t GetLogicalProcessorCacheSizeFromOS()
{
Expand All @@ -886,19 +886,19 @@ static size_t GetLogicalProcessorCacheSizeFromOS()

#ifdef _SC_LEVEL1_DCACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL1_DCACHE_SIZE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q (also applies to the old src) - what does sysconf return if there's no cache of that level? I presume it returns 0, not -1 (the doc says it returns -1 if there's an error).

CHECK_CACHE_SIZE(1)
UPDATE_CACHE_SIZE_AND_LEVEL(1)
#endif
#ifdef _SC_LEVEL2_CACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL2_CACHE_SIZE);
CHECK_CACHE_SIZE(2)
UPDATE_CACHE_SIZE_AND_LEVEL(2)
#endif
#ifdef _SC_LEVEL3_CACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL3_CACHE_SIZE);
CHECK_CACHE_SIZE(3)
UPDATE_CACHE_SIZE_AND_LEVEL(3)
#endif
#ifdef _SC_LEVEL4_CACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL4_CACHE_SIZE);
CHECK_CACHE_SIZE(4)
UPDATE_CACHE_SIZE_AND_LEVEL(4)
#endif

#if defined(TARGET_LINUX) && !defined(HOST_ARM) && !defined(HOST_X86)
Expand Down Expand Up @@ -926,7 +926,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS()

if (ReadMemoryValueFromFile(path_to_level_file, &level))
{
CHECK_CACHE_SIZE(level)
UPDATE_CACHE_SIZE_AND_LEVEL(level)
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/pal/src/misc/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ ReadMemoryValueFromFile(const char* filename, uint64_t* val)
return result;
}

#define CHECK_CACHE_SIZE(CACHE_LEVEL) if (size > cacheSize) { cacheSize = size; cacheLevel = CACHE_LEVEL; }
#define UPDATE_CACHE_SIZE_AND_LEVEL(CACHE_LEVEL) if (size > cacheSize) { cacheSize = size; cacheLevel = CACHE_LEVEL; }

size_t
PALAPI
Expand All @@ -551,19 +551,19 @@ PAL_GetLogicalProcessorCacheSizeFromOS()

#ifdef _SC_LEVEL1_DCACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL1_DCACHE_SIZE);
CHECK_CACHE_SIZE(1)
UPDATE_CACHE_SIZE_AND_LEVEL(1)
#endif
#ifdef _SC_LEVEL2_CACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL2_CACHE_SIZE);
CHECK_CACHE_SIZE(2)
UPDATE_CACHE_SIZE_AND_LEVEL(2)
#endif
#ifdef _SC_LEVEL3_CACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL3_CACHE_SIZE);
CHECK_CACHE_SIZE(3)
UPDATE_CACHE_SIZE_AND_LEVEL(3)
#endif
#ifdef _SC_LEVEL4_CACHE_SIZE
size = ( size_t) sysconf(_SC_LEVEL4_CACHE_SIZE);
CHECK_CACHE_SIZE(4)
UPDATE_CACHE_SIZE_AND_LEVEL(4)
#endif

#if defined(TARGET_LINUX) && !defined(HOST_ARM) && !defined(HOST_X86)
Expand Down Expand Up @@ -591,7 +591,7 @@ PAL_GetLogicalProcessorCacheSizeFromOS()

if (ReadMemoryValueFromFile(path_to_level_file, &level))
{
CHECK_CACHE_SIZE(level)
UPDATE_CACHE_SIZE_AND_LEVEL(level)
}
else
{
Expand Down