Excellent idea -- applied. Thanks!
On Apr 22, 2007, at 2:30 PM, Bert Wesarg wrote:
> By setting the environment variable PLPA_SYSFS_MOUNT
> to a valid directory, its possible to test the topology interface
> without
> a kernel that provides this. The default is set to "/sys".
>
> This is also useful for non default mount points for sysfs.
>
> Initialy, I passed &argc, and &argv to the PLPA_NAME(plpa_init)() and
> further down to PLPA_NAME(map_init)(), but when not called by the user
> this would be always (NULL, NULL), so an environment variable
> sounds better.
>
> Bert
> ---
>
> src/libplpa/plpa_map.c | 21 +++++++++++++++------
> 1 files changed, 15 insertions(+), 6 deletions(-)
>
> diff --quilt old/src/libplpa/plpa_map.c new/src/libplpa/plpa_map.c
> --- old/src/libplpa/plpa_map.c
> +++ new/src/libplpa/plpa_map.c
> @@ -159,24 +159,25 @@ static void clear_cache(void)
> max_processor = -1;
> max_socket = -1;
> max_core_overall = -1;
> }
>
> -static void load_cache(void)
> +static void load_cache(const char *sysfs_mount)
> {
> int i, j, k, invalid_entry, fd;
> char path[PATH_MAX], buf[8];
>
> /* Check for the parent directory */
> - if ( access("/sys/devices/system/cpu", R_OK|X_OK) ) {
> + sprintf(path, "%s/devices/system/cpu", sysfs_mount);
> + if ( access(path, R_OK|X_OK) ) {
> return;
> }
>
> /* Go through and find the max processor ID */
> for (max_processor = 0; max_processor < PLPA_BITMASK_CPU_MAX;
> ++max_processor) {
> - sprintf(path, "/sys/devices/system/cpu/cpu%d", max_processor);
> + sprintf(path, "%s/devices/system/cpu/cpu%d", sysfs_mount,
> max_processor);
> if ( access(path, R_OK|X_OK) ) {
> break;
> }
> }
> --max_processor;
> @@ -208,11 +209,11 @@ static void load_cache(void)
> max_core[i] = -1;
> }
>
> /* Build a cached map of (socket,core) tuples */
> for ( i = 0; i <= max_processor; i++ ) {
> - sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_id", i);
> + sprintf(path, "%s/devices/system/cpu/cpu%d/topology/core_id",
> sysfs_mount, i);
> fd = open(path, O_RDONLY);
> if ( fd < 0 ) {
> clear_cache();
> return;
> }
> @@ -221,11 +222,11 @@ static void load_cache(void)
> return;
> }
> sscanf(buf, "%d", &(map_processor_id_to_tuple[i].core));
> close(fd);
>
> - sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/
> physical_package_id", i);
> + sprintf(path, "%s/devices/system/cpu/cpu%d/topology/
> physical_package_id", sysfs_mount, i);
> fd = open(path, O_RDONLY);
> if ( fd < 0 ) {
> clear_cache();
> return;
> }
> @@ -299,11 +300,19 @@ static void load_cache(void)
> /* Internal function to setup the mapping data. Guaranteed to be
> calling during PLPA_NAME(init), so we don't have to worry about
> thread safety here. */
> int PLPA_NAME(map_init)(void)
> {
> - load_cache();
> + const char *sysfs_mount = "/sys";
> + char *temp;
> +
> + temp = getenv("PLPA_SYSFS_MOUNT");
> + if (temp) {
> + sysfs_mount = temp;
> + }
> +
> + load_cache(sysfs_mount);
> return 0;
> }
>
> /* Internal function to cleanup allocated memory. Only called by one
> thread (during PLPA_NAME(finalize), so don't need to worry about
> _______________________________________________
> plpa-users mailing list
> plpa-users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/plpa-users
--
Jeff Squyres
Cisco Systems
|