[mpich2-commits] r5634 - mpich2/trunk/src/pm/smpd
jayesh at mcs.anl.gov
jayesh at mcs.anl.gov
Fri Oct 30 12:40:10 CDT 2009
Author: jayesh
Date: 2009-10-30 12:40:10 -0500 (Fri, 30 Oct 2009)
New Revision: 5634
Modified:
mpich2/trunk/src/pm/smpd/smpd.h
mpich2/trunk/src/pm/smpd/smpd_affinitize.c
mpich2/trunk/src/pm/smpd/smpd_cmd_args.c
Log:
Handling the case where we don't have info about logical procs on windows - eg: Win2K systems. If info about logical procs is not available we don't set proc affinity and allow these systems to continue working. See tickets 832,776
Modified: mpich2/trunk/src/pm/smpd/smpd.h
===================================================================
--- mpich2/trunk/src/pm/smpd/smpd.h 2009-10-30 16:24:47 UTC (rev 5633)
+++ mpich2/trunk/src/pm/smpd/smpd.h 2009-10-30 17:40:10 UTC (rev 5634)
@@ -980,7 +980,7 @@
#ifdef HAVE_WINDOWS_H
DWORD_PTR smpd_get_next_process_affinity_mask(void );
DWORD_PTR smpd_get_processor_affinity_mask(int proc_num);
-void smpd_init_affinity_table(void );
+BOOL smpd_init_affinity_table(void );
#endif
#if defined(__cplusplus)
Modified: mpich2/trunk/src/pm/smpd/smpd_affinitize.c
===================================================================
--- mpich2/trunk/src/pm/smpd/smpd_affinitize.c 2009-10-30 16:24:47 UTC (rev 5633)
+++ mpich2/trunk/src/pm/smpd/smpd_affinitize.c 2009-10-30 17:40:10 UTC (rev 5634)
@@ -39,8 +39,10 @@
DWORD_PTR smpd_get_next_process_affinity_mask()
{
DWORD_PTR Mask;
- if (s_affinity_max == 0)
+ if (s_affinity_max == 0){
+ smpd_dbg_printf("Affinity table not initialized. Returning invalid mask\n");
return 0;
+ }
Mask = s_affinity_table[s_affinity_idx % s_affinity_max];
s_affinity_idx++;
@@ -245,45 +247,62 @@
This function initilizes the affinity table. The processor assignments to processes
are distributed so as to balance the use of system resources.
*/
-void smpd_init_affinity_table()
+typedef BOOL (WINAPI *LPFN_GetLogicalProcessorInformation)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
+BOOL smpd_init_affinity_table()
{
/*
Get this process affinity mask (the system mask is unused)
*/
int count, nTableEntries;
- BOOL fSucc;
+ BOOL fSucc, retval = TRUE;
DWORD Length;
DWORD_PTR SystemMask, ReserveMask, PrimaryMask;
DWORD_PTR UsableProcessorMask;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION* pInfo = NULL;
ResourceTableEntry* pTable = NULL;
+ LPFN_GetLogicalProcessorInformation lpfn_get_logical_proc_info;
fSucc = GetProcessAffinityMask(GetCurrentProcess(), &UsableProcessorMask, &SystemMask);
- if(!fSucc)
- return;
+ if(!fSucc){
+ return FALSE;
+ }
+ /* Check if GetLogicalProcessorInformation() is available */
+ lpfn_get_logical_proc_info =
+ (LPFN_GetLogicalProcessorInformation ) GetProcAddress(GetModuleHandle(TEXT("kernel32")),
+ "GetLogicalProcessorInformation");
+ if(lpfn_get_logical_proc_info == NULL){
+ smpd_dbg_printf("GetLogicalProcessorInformation() not available\n");
+ return FALSE;
+ }
/*
Retrieve the length required to store the processor information data
*/
Length = 0;
- /* FIXME: Check return val */
- GetLogicalProcessorInformation(NULL, &Length);
- if(Length == 0)
- return;
+ /* This call will fail - however it will return the length reqd to store proc info*/
+ fSucc = lpfn_get_logical_proc_info(NULL, &Length);
+ if(Length == 0){
+ smpd_dbg_printf("GetLogicalProcessorInformation() returned invalid (0 bytes) length to store proc info\n");
+ return FALSE;
+ }
/*
Allocate the processor information buffer
*/
pInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*) malloc(Length);
- if(pInfo == NULL)
- return;
+ if(pInfo == NULL){
+ smpd_err_printf("Allocating memory for system logical proc info failed\n");
+ return FALSE;
+ }
/*
Query for the processors information
*/
- fSucc = GetLogicalProcessorInformation(pInfo, &Length);
- if(!fSucc)
- goto fn_exit;
+ fSucc = lpfn_get_logical_proc_info(pInfo, &Length);
+ if(!fSucc){
+ smpd_err_printf("GetLogicalProcessorInformation() failed (error = %d)\n", GetLastError());
+ goto fn_fail;
+ }
count = Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
@@ -293,8 +312,10 @@
qsort(pInfo, count, sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION), compare_proc_info);
pTable = (ResourceTableEntry*) malloc(count * sizeof(ResourceTableEntry));
- if (pTable == NULL)
- goto fn_exit;
+ if (pTable == NULL){
+ smpd_err_printf("Allocating memory for Resourcetableentry failed\n");
+ goto fn_fail;
+ }
/*
Initialize resource table from the sorted PROCESSOR_INFORMATION array
@@ -325,8 +346,12 @@
}
free(pTable);
-fn_exit:
+ fn_exit:
free(pInfo);
+ return retval;
+fn_fail:
+ retval = FALSE;
+ goto fn_exit;
}
/* This function returns an affinity mask corresponding to the logical processor
Modified: mpich2/trunk/src/pm/smpd/smpd_cmd_args.c
===================================================================
--- mpich2/trunk/src/pm/smpd/smpd_cmd_args.c 2009-10-30 16:24:47 UTC (rev 5633)
+++ mpich2/trunk/src/pm/smpd/smpd_cmd_args.c 2009-10-30 17:40:10 UTC (rev 5634)
@@ -445,8 +445,13 @@
smpd_dbg_printf("unable to set the ctrl handler for the smpd manager, error %d.\n", result);
}
#ifdef HAVE_WINDOWS_H
- /* FIXME: smpd_init_affinity_table() Does not return error codes if it fails */
- smpd_init_affinity_table();
+ {
+ BOOL ret;
+ ret = smpd_init_affinity_table();
+ if(!ret){
+ smpd_dbg_printf("Initializing smpd affinity table failed\n");
+ }
+ }
#endif
smpd_process.bService = SMPD_FALSE;
More information about the mpich2-commits
mailing list