Load thread metadata from the JSON file
This commit is contained in:
		
							parent
							
								
									428e0b44b8
								
							
						
					
					
						commit
						3d10bef305
					
				| @ -9,6 +9,7 @@ | |||||||
| #include "ovni.h" | #include "ovni.h" | ||||||
| #include "parson.h" | #include "parson.h" | ||||||
| #include "proc.h" | #include "proc.h" | ||||||
|  | #include "thread.h" | ||||||
| 
 | 
 | ||||||
| static JSON_Object * | static JSON_Object * | ||||||
| load_json(const char *path) | load_json(const char *path) | ||||||
| @ -45,19 +46,6 @@ check_version(JSON_Object *meta) | |||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	JSON_Value *mversion_val = json_object_get_value(meta, "model_version"); |  | ||||||
| 	if (mversion_val == NULL) { |  | ||||||
| 		err("missing attribute \"model_version\""); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	const char *mversion = json_string(mversion_val); |  | ||||||
| 	if (strcmp(mversion, OVNI_MODEL_VERSION) != 0) { |  | ||||||
| 		err("model version mismatch '%s' (expected '%s')", |  | ||||||
| 				mversion, OVNI_MODEL_VERSION); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -121,11 +109,11 @@ load_cpus(struct loom *loom, JSON_Object *meta) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int | int | ||||||
| metadata_load(const char *path, struct loom *loom, struct proc *proc) | metadata_load_proc(const char *path, struct loom *loom, struct proc *proc) | ||||||
| { | { | ||||||
| 	JSON_Object *meta = load_json(path); | 	JSON_Object *meta = load_json(path); | ||||||
| 	if (meta == NULL) { | 	if (meta == NULL) { | ||||||
| 		err("cannot load metadata from file %s", path); | 		err("cannot load proc metadata from file %s", path); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -147,3 +135,25 @@ metadata_load(const char *path, struct loom *loom, struct proc *proc) | |||||||
| 
 | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | int | ||||||
|  | metadata_load_thread(const char *path, struct thread *thread) | ||||||
|  | { | ||||||
|  | 	JSON_Object *meta = load_json(path); | ||||||
|  | 	if (meta == NULL) { | ||||||
|  | 		err("cannot load thread metadata from file %s", path); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (check_version(meta) != 0) { | ||||||
|  | 		err("version check failed"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (thread_load_metadata(thread, meta) != 0) { | ||||||
|  | 		err("cannot load thread attributes"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | |||||||
| @ -7,7 +7,9 @@ | |||||||
| #include "common.h" | #include "common.h" | ||||||
| struct loom; | struct loom; | ||||||
| struct proc; | struct proc; | ||||||
|  | struct thread; | ||||||
| 
 | 
 | ||||||
| USE_RET int metadata_load(const char *path, struct loom *loom, struct proc *proc); | USE_RET int metadata_load_proc(const char *path, struct loom *loom, struct proc *proc); | ||||||
|  | USE_RET int metadata_load_thread(const char *path, struct thread *thread); | ||||||
| 
 | 
 | ||||||
| #endif /* METADATA_H */ | #endif /* METADATA_H */ | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ | |||||||
| struct bay; | struct bay; | ||||||
| 
 | 
 | ||||||
| static struct thread * | static struct thread * | ||||||
| create_thread(struct proc *proc, const char *relpath) | create_thread(struct proc *proc, const char *tracedir, const char *relpath) | ||||||
| { | { | ||||||
| 	int tid; | 	int tid; | ||||||
| 	if (thread_relpath_get_tid(relpath, &tid) != 0) { | 	if (thread_relpath_get_tid(relpath, &tid) != 0) { | ||||||
| @ -50,6 +50,19 @@ create_thread(struct proc *proc, const char *relpath) | |||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	/* Build metadata path */ | ||||||
|  | 	char mpath[PATH_MAX]; | ||||||
|  | 	if (snprintf(mpath, PATH_MAX, "%s/%s/thread.%d.json", | ||||||
|  | 				tracedir, proc->id, tid) >= PATH_MAX) { | ||||||
|  | 		err("path too long"); | ||||||
|  | 		return NULL; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (metadata_load_thread(mpath, thread) != 0) { | ||||||
|  | 		err("cannot load metadata from %s", mpath); | ||||||
|  | 		return NULL; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if (proc_add_thread(proc, thread) != 0) { | 	if (proc_add_thread(proc, thread) != 0) { | ||||||
| 		err("failed to add thread to proc"); | 		err("failed to add thread to proc"); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| @ -94,7 +107,7 @@ create_proc(struct loom *loom, const char *tracedir, const char *relpath) | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Load metadata too */ | 	/* Load metadata too */ | ||||||
| 	if (metadata_load(mpath, loom, proc) != 0) { | 	if (metadata_load_proc(mpath, loom, proc) != 0) { | ||||||
| 		err("cannot load metadata from %s", mpath); | 		err("cannot load metadata from %s", mpath); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
| @ -185,7 +198,7 @@ create_system(struct system *sys, struct trace *trace) | |||||||
| 			return -1; | 			return -1; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		struct thread *thread = create_thread(proc, s->relpath); | 		struct thread *thread = create_thread(proc, dir, s->relpath); | ||||||
| 		if (thread == NULL) { | 		if (thread == NULL) { | ||||||
| 			err("create_thread failed"); | 			err("create_thread failed"); | ||||||
| 			return -1; | 			return -1; | ||||||
|  | |||||||
| @ -152,6 +152,11 @@ thread_init_end(struct thread *th) | |||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if (th->meta == NULL) { | ||||||
|  | 		err("missing metadata for thread %s", th->id); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for (int i = 0; i < TH_CHAN_MAX; i++) { | 	for (int i = 0; i < TH_CHAN_MAX; i++) { | ||||||
| 		chan_init(&th->chan[i], CHAN_SINGLE, | 		chan_init(&th->chan[i], CHAN_SINGLE, | ||||||
| 				chan_fmt, th->gindex, chan_name[i]); | 				chan_fmt, th->gindex, chan_name[i]); | ||||||
| @ -439,3 +444,16 @@ thread_migrate_cpu(struct thread *th, struct cpu *cpu) | |||||||
| 
 | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | int | ||||||
|  | thread_load_metadata(struct thread *thread, JSON_Object *meta) | ||||||
|  | { | ||||||
|  | 	if (thread->meta != NULL) { | ||||||
|  | 		err("thread %s already loaded metadata", thread->id); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	thread->meta = meta; | ||||||
|  | 
 | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ | |||||||
| #include "common.h" | #include "common.h" | ||||||
| #include "extend.h" | #include "extend.h" | ||||||
| #include "uthash.h" | #include "uthash.h" | ||||||
|  | #include "parson.h" | ||||||
| struct bay; | struct bay; | ||||||
| struct cpu; | struct cpu; | ||||||
| struct mux; | struct mux; | ||||||
| @ -70,6 +71,9 @@ struct thread { | |||||||
| 
 | 
 | ||||||
| 	struct chan chan[TH_CHAN_MAX]; | 	struct chan chan[TH_CHAN_MAX]; | ||||||
| 
 | 
 | ||||||
|  | 	/* Metadata */ | ||||||
|  | 	JSON_Object *meta; | ||||||
|  | 
 | ||||||
| 	struct extend ext; | 	struct extend ext; | ||||||
| 
 | 
 | ||||||
| 	UT_hash_handle hh; /* threads in the process */ | 	UT_hash_handle hh; /* threads in the process */ | ||||||
| @ -78,6 +82,7 @@ struct thread { | |||||||
| USE_RET int thread_relpath_get_tid(const char *relpath, int *tid); | USE_RET int thread_relpath_get_tid(const char *relpath, int *tid); | ||||||
| USE_RET int thread_init_begin(struct thread *thread, const char *relpath); | USE_RET int thread_init_begin(struct thread *thread, const char *relpath); | ||||||
| USE_RET int thread_init_end(struct thread *thread); | USE_RET int thread_init_end(struct thread *thread); | ||||||
|  | USE_RET int thread_load_metadata(struct thread *thread, JSON_Object *meta); | ||||||
| USE_RET int thread_set_state(struct thread *th, enum thread_state state); | USE_RET int thread_set_state(struct thread *th, enum thread_state state); | ||||||
| USE_RET int thread_set_cpu(struct thread *th, struct cpu *cpu); | USE_RET int thread_set_cpu(struct thread *th, struct cpu *cpu); | ||||||
| USE_RET int thread_unset_cpu(struct thread *th); | USE_RET int thread_unset_cpu(struct thread *th); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user