2 #include "libtest_porting_abstraction_layer_internal.h"
8 /****************************************************************************/
9 #if( defined _WIN32 && !defined KERNEL_MODE && NTDDI_VERSION >= NTDDI_WIN7 )
11 #ifdef LIBTEST_PAL_GET_LOGICAL_CORE_IDS
12 #error More than one porting abstraction layer matches current platform in "libtest_porting_abstraction_layer_get_full_logical_processor_set.c".
15 #define LIBTEST_PAL_GET_LOGICAL_CORE_IDS
17 void libtest_pal_get_full_logical_processor_set( struct lfds710_list_asu_state *list_of_logical_processors,
18 struct libshared_memory_state *ms )
29 logical_processor_number,
30 windows_processor_group_number;
32 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
36 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
37 LFDS710_PAL_ASSERT( ms != NULL );
39 lfds710_list_asu_init_valid_on_current_logical_core( list_of_logical_processors, NULL );
41 rv = GetLogicalProcessorInformationEx( RelationGroup, slpie_buffer, &slpie_length );
42 slpie_buffer = libshared_memory_alloc_from_most_free_space_node( ms, slpie_length, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
43 rv = GetLogicalProcessorInformationEx( RelationGroup, slpie_buffer, &slpie_length );
45 while( offset < slpie_length )
47 slpie = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) ( (char unsigned *) slpie_buffer + offset );
49 offset += slpie->Size;
51 if( slpie->Relationship == RelationGroup )
52 for( windows_processor_group_number = 0 ; windows_processor_group_number < slpie->Group.ActiveGroupCount ; windows_processor_group_number++ )
53 for( logical_processor_number = 0 ; logical_processor_number < sizeof(KAFFINITY) * BITS_PER_BYTE ; logical_processor_number++ )
55 bitmask = (lfds710_pal_uint_t) 1 << logical_processor_number;
57 // TRD : if we've found a processor for this group, add it to the list
58 if( slpie->Group.GroupInfo[windows_processor_group_number].ActiveProcessorMask & bitmask )
59 libtest_misc_pal_helper_add_logical_processor_to_list_of_logical_processors( list_of_logical_processors, ms, logical_processor_number, windows_processor_group_number );
72 /****************************************************************************/
73 #if( defined _WIN32 && !defined KERNEL_MODE && NTDDI_VERSION >= NTDDI_WINXP && NTDDI_VERSION < NTDDI_WIN7 )
75 #ifdef LIBTEST_PAL_GET_LOGICAL_CORE_IDS
76 #error More than one porting abstraction layer matches current platform in "libtest_porting_abstraction_layer_get_full_logical_processor_set.c".
79 #define LIBTEST_PAL_GET_LOGICAL_CORE_IDS
81 void libtest_pal_get_full_logical_processor_set( struct lfds710_list_asu_state *list_of_logical_processors,
82 struct libshared_memory_state *ms )
91 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
97 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
98 LFDS710_PAL_ASSERT( ms != NULL );
100 lfds710_list_asu_init_valid_on_current_logical_core( list_of_logical_processors, NULL, NULL );
102 *number_logical_processors = 0;
104 GetLogicalProcessorInformation( slpi, &slpi_length );
105 slpi = libshared_memory_alloc_from_most_free_space_node( ms, slpi_length, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
106 GetLogicalProcessorInformation( slpi, &slpi_length );
107 number_slpi = slpi_length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
109 for( loop = 0 ; loop < number_slpi ; loop++ )
110 if( (slpi+loop)->Relationship == RelationProcessorCore )
111 for( logical_processor_number = 0 ; logical_processor_number < sizeof(ULONG_PTR) * BITS_PER_BYTE ; logical_processor_number++ )
113 bitmask = 1 << logical_processor_number;
115 if( (slpi+loop)->ProcessorMask & bitmask )
116 libtest_misc_pal_helper_add_logical_processor_to_list_of_logical_processors( list_of_logical_processors, ms, logical_processor_number, windows_processor_group_number );
127 /****************************************************************************/
128 #if( defined _WIN32 && defined KERNEL_MODE && NTDDI_VERSION >= NTDDI_WIN7 )
130 #ifdef LIBTEST_PAL_GET_LOGICAL_CORE_IDS
131 #error More than one porting abstraction layer matches current platform in "libtest_porting_abstraction_layer_get_full_logical_processor_set.c".
134 #define LIBTEST_PAL_GET_LOGICAL_CORE_IDS
136 void libtest_pal_get_full_logical_processor_set( struct lfds710_list_asu_state *list_of_logical_processors,
137 struct libshared_memory_state *ms )
141 logical_processor_number,
142 windows_processor_group_number;
147 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
149 *slpie_buffer = NULL;
155 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
156 LFDS710_PAL_ASSERT( ms != NULL );
158 lfds710_list_asu_init_valid_on_current_logical_core( list_of_logical_processors, NULL );
160 rv = KeQueryLogicalProcessorRelationship( NULL, RelationGroup, slpie_buffer, &slpie_length );
161 slpie_buffer = libshared_memory_alloc_from_most_free_space_node( ms, slpie_length, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
162 rv = KeQueryLogicalProcessorRelationship( NULL, RelationGroup, slpie_buffer, &slpie_length );
164 while( offset < slpie_length )
166 slpie = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) ( (char unsigned *) slpie_buffer + offset );
168 offset += slpie->Size;
170 if( slpie->Relationship == RelationGroup )
171 for( windows_processor_group_number = 0 ; windows_processor_group_number < slpie->Group.ActiveGroupCount ; windows_processor_group_number++ )
172 for( logical_processor_number = 0 ; logical_processor_number < sizeof(KAFFINITY) * BITS_PER_BYTE ; logical_processor_number++ )
174 bitmask = (lfds710_pal_uint_t) 1 << logical_processor_number;
176 // TRD : if we've found a processor for this group, add it to the list
177 if( slpie->Group.GroupInfo[windows_processor_group_number].ActiveProcessorMask & bitmask )
178 libtest_misc_pal_helper_add_logical_processor_to_list_of_logical_processors( list_of_logical_processors, ms, logical_processor_number, windows_processor_group_number );
191 /****************************************************************************/
192 #if( defined _WIN32 && defined KERNEL_MODE && NTDDI_VERSION >= NTDDI_WINXP && NTDDI_VERSION < NTDDI_WIN7 )
194 #ifdef LIBTEST_PAL_GET_LOGICAL_CORE_IDS
195 #error More than one porting abstraction layer matches current platform in "libtest_porting_abstraction_layer_get_full_logical_processor_set.c".
198 #define LIBTEST_PAL_GET_LOGICAL_CORE_IDS
200 void libtest_pal_get_full_logical_processor_set( struct lfds710_list_asu_state *list_of_logical_processors,
201 struct libshared_memory_state *ms )
206 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
207 LFDS710_PAL_ASSERT( ms != NULL );
209 /* TRD : in XP, KeNumberProcessors is a CCHAR indicating the number of processors
210 the docs say nothing about whether the actual logical processor numbers are contigious or not...
211 ...which is absolutely normal for MS docs on anything to do with CPU topology - bloody useless
212 just to make the point about bloody useless, this same variable is only a CCHAR in XP
213 prior to XP, it is a pointer to a CCHAR, where that CCHAR holds the same data
218 for( loop = 0 ; loop < KeNumberProcessors ; loop++ )
219 libtest_misc_pal_helper_add_logical_processor_to_list_of_logical_processors( list_of_logical_processors, ms, loop, 0 );
230 /****************************************************************************/
231 #if( defined __linux__ && defined __STDC__ and __STDC_HOSTED__ == 1 )
233 #ifdef LIBTEST_PAL_GET_LOGICAL_CORE_IDS
234 #error More than one porting abstraction layer matches current platform in "libtest_porting_abstraction_layer_get_full_logical_processor_set.c".
237 #define LIBTEST_PAL_GET_LOGICAL_CORE_IDS
239 void libtest_pal_get_full_logical_processor_set( struct lfds710_list_asu_state *list_of_logical_processors,
240 struct libshared_memory_state *ms )
249 int long long unsigned
250 logical_processor_number;
252 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
253 LFDS710_PAL_ASSERT( ms != NULL );
255 lfds710_list_asu_init_valid_on_current_logical_core( list_of_logical_processors, NULL );
257 diskfile = fopen( "/proc/cpuinfo", "r" );
259 if( diskfile != NULL )
261 setbuf( diskfile, diskbuffer );
263 while( NULL != fgets(string, 1024, diskfile) )
264 if( 1 == sscanf(string, "processor : %llu", &logical_processor_number) )
265 libtest_misc_pal_helper_add_logical_processor_to_list_of_logical_processors( list_of_logical_processors, ms, logical_processor_number, 0 );
279 /****************************************************************************/
280 #if( !defined LIBTEST_PAL_GET_LOGICAL_CORE_IDS )
282 #error No matching porting abstraction layer in "libtest_porting_abstraction_layer_get_full_logical_processor_set.c".