[ofa-general] Re: [PATCH] [2 of 10] [REVISED] mesh analysis - mesh_t data structure

Sasha Khapyorsky sashak at voltaire.com
Sat Dec 20 12:11:53 PST 2008


Hi Bob,

On 12:00 Wed 10 Dec     , Robert Pearson wrote:
> 
> This patch:
> 
>       - creates a data structure, mesh_t, that holds per mesh information
> 
>       - adds a pointer to this structure in lash_t
> 
>       - creates methods to create, cleanup and destroy the object.
> 
>       - adds calls in osm_ucast_lash.c to call these.

osm_mesh_create() is called when lash->num_switches still be zero - as
result a memory for mesh buffers is not allocated actually. I reworked
this patch as below and rebased the rest.

Sasha

>From 304739705a93201ed6f0c95f279b57962b71c4f8 Mon Sep 17 00:00:00 2001
From: Robert Pearson <rpearson at systemfabricworks.com>
Date: Wed, 10 Dec 2008 12:00:21 -0600
Subject: [PATCH] mesh analysis - mesh_t data structure

Sasha,

Here is a revised mesh patch #2 that incorporates changes based on your
comments.

The purpose of this patch is to create a per fabric data structure and
methods.

This patch:

      - creates a data structure, mesh_t, that holds per mesh information

      - adds a pointer to this structure in lash_t

      - creates methods to create, cleanup and destroy the object.

      - adds calls in osm_ucast_lash.c to call these.

Regards,

Bob Pearson

Signed-off-by: Bob Pearson <rpearson at systemfabricworks.com>
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/opensm/osm_mesh.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/opensm/opensm/osm_mesh.c b/opensm/opensm/osm_mesh.c
index 486e6b4..0786701 100644
--- a/opensm/opensm/osm_mesh.c
+++ b/opensm/opensm/osm_mesh.c
@@ -41,6 +41,7 @@
 #endif				/* HAVE_CONFIG_H */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <opensm/osm_switch.h>
 #include <opensm/osm_opensm.h>
 #include <opensm/osm_log.h>
@@ -48,14 +49,73 @@
 #include <opensm/osm_ucast_lash.h>
 
 /*
+ * per fabric mesh info
+ */
+typedef struct _mesh {
+	int num_class;			/* number of switch classes */
+	int *class_type;		/* index of first switch found for each class */
+	int *class_count;		/* population of each class */
+	int dimension;			/* mesh dimension */
+	int *size;			/* an array to hold size of mesh */
+} mesh_t;
+
+/*
+ * osm_mesh_delete - free per mesh resources
+ */
+static void mesh_delete(mesh_t *mesh)
+{
+	if (mesh) {
+		if (mesh->class_type)
+			free(mesh->class_type);
+
+		if (mesh->class_count)
+			free(mesh->class_count);
+
+		free(mesh);
+	}
+}
+
+/*
+ * osm_mesh_create - allocate per mesh resources
+ */
+static mesh_t *mesh_create(lash_t *p_lash)
+{
+	osm_log_t *p_log = &p_lash->p_osm->log;
+	mesh_t *mesh;
+
+	if(!(mesh = calloc(1, sizeof(mesh_t))))
+		goto err;
+
+	if (!(mesh->class_type = calloc(p_lash->num_switches, sizeof(int))))
+		goto err;
+
+	if (!(mesh->class_count = calloc(p_lash->num_switches, sizeof(int))))
+		goto err;
+
+	return mesh;
+
+err:
+	mesh_delete(mesh);
+	OSM_LOG(p_log, OSM_LOG_ERROR, "Failed allocating mesh - out of memory\n");
+	return NULL;
+}
+
+/*
  * osm_do_mesh_analysis
  */
 int osm_do_mesh_analysis(lash_t *p_lash)
 {
 	osm_log_t *p_log = &p_lash->p_osm->log;
+	mesh_t *mesh;
 
 	OSM_LOG_ENTER(p_log);
 
+	mesh = mesh_create(p_lash);
+	if (!mesh)
+		return -1;
+
+	mesh_delete(mesh);
+
 	OSM_LOG_EXIT(p_log);
 	return 0;
 }
-- 
1.6.0.4.766.g6fc4a




More information about the general mailing list