浏览代码

Make PAPI report more verbose errors

Samuel Thibault 4 年之前
父节点
当前提交
c56c9d02a6
共有 1 个文件被更改,包括 15 次插入9 次删除
  1. 15 9
      src/core/perfmodel/energy_model.c

+ 15 - 9
src/core/perfmodel/energy_model.c

@@ -43,7 +43,7 @@
 #endif
 #endif
 #endif
 #endif
 
 
-#define ERROR_RETURN(retval) do { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__);  return(retval); } while (0)
+#define ERROR_RETURN(retval, function) do { PAPI_perror(function); fprintf(stderr, "Error %d %s:line %d\n", retval,__FILE__,__LINE__);  return(retval); } while (0)
 
 
 #if 0
 #if 0
 #define debug(fmt, ...) printf(fmt, ## __VA_ARGS__)
 #define debug(fmt, ...) printf(fmt, ## __VA_ARGS__)
@@ -101,11 +101,11 @@ int starpu_energy_start(int workerid STARPU_ATTRIBUTE_UNUSED, enum starpu_worker
 		nsockets = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PACKAGE);
 		nsockets = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PACKAGE);
 
 
 		if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
 		if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_library_init");
 
 
 		/* Creating the eventset */
 		/* Creating the eventset */
 		if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
 		if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_create_eventset");
 
 
 		int i;
 		int i;
 		for (i = 0 ; i < nsockets ; i ++ )
 		for (i = 0 ; i < nsockets ; i ++ )
@@ -113,19 +113,25 @@ int starpu_energy_start(int workerid STARPU_ATTRIBUTE_UNUSED, enum starpu_worker
 			/* return the index of socket */
 			/* return the index of socket */
 			hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, i);
 			hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, i);
 			if ( (retval = add_event(EventSet, obj->os_index)) != PAPI_OK)
 			if ( (retval = add_event(EventSet, obj->os_index)) != PAPI_OK)
-				ERROR_RETURN(retval);
+			{
+				if (retval == PAPI_EPERM)
+					_STARPU_DISP("PAPI could not access counters due to permissions errors. Perhaps your system requires to run measurements as root?\n");
+				else if (retval == PAPI_ENOEVNT)
+					_STARPU_DISP("PAPI could not access counters. Perhaps your system requires to run measurements as root?\n");
+				ERROR_RETURN(retval, "PAPI_add_named_event");
+			}
 		}
 		}
 
 
 		/* get the number of events in the event set */
 		/* get the number of events in the event set */
 		number = 0;
 		number = 0;
 		if ( (retval = PAPI_list_events(EventSet, NULL, &number)) != PAPI_OK)
 		if ( (retval = PAPI_list_events(EventSet, NULL, &number)) != PAPI_OK)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_list_events");
 
 
 		debug("There are %d events in the event set\n", number);
 		debug("There are %d events in the event set\n", number);
 
 
 		/* Start counting */
 		/* Start counting */
 		if ( (retval = PAPI_start(EventSet)) != PAPI_OK)
 		if ( (retval = PAPI_start(EventSet)) != PAPI_OK)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_start");
 
 
 		return retval;
 		return retval;
 	}
 	}
@@ -181,7 +187,7 @@ int starpu_energy_stop(struct starpu_perfmodel *model, struct starpu_task *task,
 
 
 		/* Stop counting and store the values into the array */
 		/* Stop counting and store the values into the array */
 		if ( (retval = PAPI_stop(EventSet, values)) != PAPI_OK)
 		if ( (retval = PAPI_stop(EventSet, values)) != PAPI_OK)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_stop");
 
 
 		int k,s;
 		int k,s;
 
 
@@ -200,11 +206,11 @@ int starpu_energy_stop(struct starpu_perfmodel *model, struct starpu_task *task,
 
 
 		/*removes all events from a PAPI event set */
 		/*removes all events from a PAPI event set */
 		if ( (retval = PAPI_cleanup_eventset(EventSet)) != PAPI_OK)
 		if ( (retval = PAPI_cleanup_eventset(EventSet)) != PAPI_OK)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_cleanup_eventset");
 
 
 		/*deallocates the memory associated with an empty PAPI EventSet*/
 		/*deallocates the memory associated with an empty PAPI EventSet*/
 		if ( (retval = PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
 		if ( (retval = PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
-			ERROR_RETURN(retval);
+			ERROR_RETURN(retval, "PAPI_destroy_eventset");
 
 
 		break;
 		break;
 	}
 	}