8 /****************************************************************************/
9 #if( defined _WIN32 && !defined _KERNEL_MODE && NTDDI_VERSION >= NTDDI_WIN7 )
11 /* TRD : _WIN32 indicates 64-bit or 32-bit Windows
12 !_KERNEL_MODE indicates Windows user-mode
13 NTDDI_VERSION indicates Windows version
14 - GetLogicalProcessorInformationEx requires Windows 7
17 #ifdef TEST_PAL_GET_LOGICAL_CORE_IDS
18 #error More than one porting abstraction layer matches current platform in test_porting_abstraction_layer_get_logical_core_ids.c
21 #define TEST_PAL_GET_LOGICAL_CORE_IDS
23 void test_pal_get_logical_core_ids( struct lfds700_list_asu_state *lasus )
35 logical_processor_number,
36 windows_logical_processor_group_number;
38 struct lfds700_misc_prng_state
41 struct test_pal_logical_processor
44 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
47 assert( lasus != NULL );
49 lfds700_misc_prng_init( &ps );
51 lfds700_list_asu_init_valid_on_current_logical_core( lasus, NULL, NULL );
53 rv = GetLogicalProcessorInformationEx( RelationGroup, slpie, &slpie_length );
54 slpie = malloc( slpie_length );
55 rv = GetLogicalProcessorInformationEx( RelationGroup, slpie, &slpie_length );
56 number_slpie = slpie_length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX);
58 for( loop = 0 ; loop < number_slpie ; loop++ )
59 if( (slpie+loop)->Relationship == RelationGroup )
60 for( windows_logical_processor_group_number = 0 ; windows_logical_processor_group_number < (slpie+loop)->Group.ActiveGroupCount ; windows_logical_processor_group_number++ )
61 for( logical_processor_number = 0 ; logical_processor_number < sizeof(KAFFINITY) * BITS_PER_BYTE ; logical_processor_number++ )
63 bitmask = (lfds700_pal_uint_t) 1 << logical_processor_number;
65 // TRD : if we've found a processor for this group, add it to the list
66 if( (slpie+loop)->Group.GroupInfo[windows_logical_processor_group_number].ActiveProcessorMask & bitmask )
68 lp = util_aligned_malloc( sizeof(struct test_pal_logical_processor), LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
70 lp->logical_processor_number = logical_processor_number;
71 lp->windows_logical_processor_group_number = windows_logical_processor_group_number;
73 LFDS700_LIST_ASU_SET_VALUE_IN_ELEMENT( lp->lasue, lp );
74 lfds700_list_asu_insert_at_start( lasus, &lp->lasue, &ps );
89 /****************************************************************************/
90 #if( defined _WIN32 && !defined _KERNEL_MODE && NTDDI_VERSION >= NTDDI_WINXP && NTDDI_VERSION < NTDDI_WIN7 )
92 /* TRD : _WIN32 indicates 64-bit or 32-bit Windows
93 !_KERNEL_MODE indicates Windows user-mode
94 NTDDI_VERSION indicates Windows version
95 - GetLogicalProcessorInformation requires XP SP3
98 #ifdef TEST_PAL_GET_LOGICAL_CORE_IDS
99 #error More than one porting abstraction layer matches current platform in test_porting_abstraction_layer_get_logical_core_ids.c
102 #define TEST_PAL_GET_LOGICAL_CORE_IDS
104 void test_pal_get_logical_core_ids( struct lfds700_list_asu_state *lasus )
113 struct lfds700_misc_prng_state
116 struct test_pal_logical_processor
119 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
125 assert( lasus != NULL );
127 lfds700_misc_prng_init( &ps );
129 lfds700_list_asu_init_valid_on_current_logical_core( lasus, NULL, NULL );
131 *number_logical_processors = 0;
133 GetLogicalProcessorInformation( slpi, &slpi_length );
134 slpi = malloc( slpi_length );
135 GetLogicalProcessorInformation( slpi, &slpi_length );
136 number_slpi = slpi_length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
138 for( loop = 0 ; loop < number_slpi ; loop++ )
139 if( (slpi+loop)->Relationship == RelationProcessorCore )
140 for( logical_processor_number = 0 ; logical_processor_number < sizeof(ULONG_PTR) * BITS_PER_BYTE ; logical_processor_number++ )
142 bitmask = 1 << logical_processor_number;
144 if( (slpi+loop)->ProcessorMask & bitmask )
146 lp = util_aligned_malloc( sizeof(struct test_pal_logical_processor), LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
148 lp->logical_processor_number = logical_processor_number;
149 lp->windows_logical_processor_group_number = 0;
151 LFDS700_LIST_ASU_SET_VALUE_IN_ELEMENT( lp->lasue, lp );
152 lfds700_list_asu_insert_at_start( lasus, &lp->lasue, &ps );
166 /****************************************************************************/
167 #if( defined __linux__ )
169 /* TRD : __linux__ indicates Linux
170 __STDC__ indicates Standard Library
171 __STDC_HOSTED__ indicates Standard Library hosted implementation
172 - fopen requires a Standard Library hosted environment
173 - setbuf requires a Standard Library hosted environment
174 - fgets requires a Standard Library hosted environment
175 - sscanf requires a Standard Library hosted environment
176 - fclose requires a Standard Library hosted environment
179 #ifdef TEST_PAL_GET_LOGICAL_CORE_IDS
180 #error More than one porting abstraction layer matches current platform in test_porting_abstraction_layer_get_logical_core_ids.c
183 #define TEST_PAL_GET_LOGICAL_CORE_IDS
185 void test_pal_get_logical_core_ids( struct lfds700_list_asu_state *lasus )
194 int long long unsigned
195 logical_processor_number;
197 struct lfds700_misc_prng_state
200 struct test_pal_logical_processor
203 assert( lasus != NULL );
205 lfds700_misc_prng_init( &ps );
207 lfds700_list_asu_init_valid_on_current_logical_core( lasus, NULL, NULL );
209 diskfile = fopen( "/proc/cpuinfo", "r" );
211 if( diskfile != NULL )
213 setbuf( diskfile, diskbuffer );
215 while( NULL != fgets(string, 1024, diskfile) )
216 if( 1 == sscanf(string, "processor : %llu", &logical_processor_number) )
218 lp = util_aligned_malloc( sizeof(struct test_pal_logical_processor), LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
220 lp->logical_processor_number = (lfds700_pal_uint_t) logical_processor_number;
221 lp->windows_logical_processor_group_number = 0;
223 LFDS700_LIST_ASU_SET_VALUE_IN_ELEMENT( lp->lasue, lp );
224 lfds700_list_asu_insert_at_start( lasus, &lp->lasue, &ps );
239 /****************************************************************************/
240 #if( !defined TEST_PAL_GET_LOGICAL_CORE_IDS )
242 #error test_pal_get_logical_core_ids() not implemented for this platform.