From 28b7f1f95510fe2efa30fc2fb4b4d27826da931e Mon Sep 17 00:00:00 2001 From: alegrand Date: Tue, 16 Nov 2004 22:04:45 +0000 Subject: [PATCH] Renamed host to cpu. That was really confusing. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@518 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 4 +- include/Makefile.am | 1 + src/Makefile.am | 8 +++- src/include/surf/surf.h | 31 ++++++------ src/surf/cpu.c | 104 ++++++++++++++++++++++++++++++---------- src/surf/cpu_private.h | 10 ++-- src/surf/surf.c | 4 +- src/surf/surf_private.h | 2 +- testsuite/Makefile.am | 3 +- 9 files changed, 116 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 235a12997d..aa8cc5a053 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,8 +4,8 @@ to 'make check' overthere yet. 2004-11-15 Arnaud Legrand - - Trace manager now written. It uses a heap structure and is therfore - expected to be efficient. It may however be speed up (particularly + - Trace manager now written. It uses a heap structure and is therefore + expected to be efficient. It may however be speeded up (particularly when many events occur at the same date) by using red and black trees. One day maybe... - Max-min linear system solver written. It uses a sparse matrix diff --git a/include/Makefile.am b/include/Makefile.am index ab8858fc34..66af137434 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -12,6 +12,7 @@ nobase_include_HEADERS = \ \ surf/maxmin.h \ surf/trace_mgr.h \ + surf/surf.h \ \ gras/core.h \ gras/datadesc.h gras/transport.h \ diff --git a/src/Makefile.am b/src/Makefile.am index 7e681b1ed1..d8c507b33a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,6 +23,8 @@ EXTRA_DIST= \ \ surf/maxmin_private.h \ surf/trace_mgr_private.h \ + surf/surf_private.h \ + surf/cpu_private.h \ \ gras/Transport/transport_interface.h \ gras/Virtu/virtu_interface.h \ @@ -92,8 +94,10 @@ COMMON_S=\ xbt/module.c \ xbt/config.c \ \ - surf/maxmin.c \ - surf/trace_mgr.c \ + surf/maxmin.c \ + surf/trace_mgr.c \ + surf/surf.c \ + surf/cpu.c \ \ gras/Transport/transport.c gras/Transport/transport_private.h gras/Transport/transport_plugin_buf.c \ \ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index c998d3e2b8..536a63e86a 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -47,8 +47,13 @@ typedef struct surf_action { typedef struct surf_resource { void (*parse_file)(const char *file); void *(*name_service)(const char *name); + const char *(*get_resource_name)(void *resource_id); + + /* surf_action_t (*action_new)(void *callback); */ + /* Not defined here. Actions have to be created by actually + performing it and prototype may therefore vary with the resource + implementation */ - surf_action_t (*action_new)(void *callback); e_surf_action_state_t (*action_get_state)(surf_action_t action); void (*action_free)(surf_action_t * action); /* Call it when you're done with this action */ void (*action_cancel)(surf_action_t action); /* remove the variables from the linear system if needed */ @@ -65,32 +70,30 @@ typedef struct surf_resource { /**************************************/ /* Implementations of resource object */ /**************************************/ -/* Host resource */ +/* Cpu resource */ typedef enum { - SURF_HOST_ON = 1, /* Ready */ - SURF_HOST_OFF = 0, /* Running */ -} e_surf_host_state_t; + SURF_CPU_ON = 1, /* Ready */ + SURF_CPU_OFF = 0, /* Running */ +} e_surf_cpu_state_t; -typedef struct surf_host_resource { +typedef struct surf_cpu_resource { s_surf_resource_t resource; - void (*execute)(void *host, xbt_maxmin_float_t size, surf_action_t action); - e_surf_host_state_t (*get_state)(void *host); -} s_surf_host_resource_t, *surf_host_resource_t; -extern surf_host_resource_t surf_host_resource; + surf_action_t (*execute)(void *cpu, xbt_maxmin_float_t size); + e_surf_cpu_state_t (*get_state)(void *cpu); +} s_surf_cpu_resource_t, *surf_cpu_resource_t; +extern surf_cpu_resource_t surf_cpu_resource; /* Network resource */ typedef struct surf_network_resource { s_surf_resource_t resource; - surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size, - surf_action_t action); + surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size); } s_surf_network_resource_t, surf_network_resource_t; extern surf_network_resource_t surf_network_resource; /* Timer resource */ typedef struct surf_timer_resource { s_surf_resource_t resource; - surf_action_t (*wait)(void *host, void *dst, xbt_maxmin_float_t size, - surf_action_t surf); + surf_action_t (*wait)(void *cpu, void *dst, xbt_maxmin_float_t size); } s_surf_timer_resource_t, surf_timer_resource_t; extern surf_timer_resource_t surf_timer_resource; diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 9b63b8d676..3f4c5100e4 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -3,17 +3,67 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU LGPL) which comes with this package. */ -#include "host_private.h" +#include "cpu_private.h" +#include "xbt/dict.h" + +surf_cpu_resource_t surf_cpu_resource = NULL; +static xbt_dict_t cpu_set = NULL; +static lmm_system_t sys = NULL; + +typedef struct cpu { + const char *name; + xbt_maxmin_float_t power_scale; + xbt_maxmin_float_t current_power; + tmgr_trace_t power_trace; + e_surf_action_state_t current_state; + tmgr_trace_t state_trace; + lmm_constraint_t constraint; +} s_cpu_t, *cpu_t; + +/* power_scale is the basic power of the cpu when the cpu is + completely available. initial_power is therefore expected to be + comprised between 0.0 and 1.0, just as the values of power_trace. + state_trace values mean SURF_CPU_ON if >0 and SURF_CPU_OFF + otherwise. +*/ + +static void *new_cpu(const char *name, xbt_maxmin_float_t power_scale, + xbt_maxmin_float_t initial_power, tmgr_trace_t power_trace, + e_surf_cpu_state_t initial_state, tmgr_trace_t state_trace) +{ + cpu_t cpu = xbt_new0(s_cpu_t,1); + + cpu->name = name; + cpu->power_scale = power_scale; + cpu->current_power = initial_power; + cpu->power_trace = power_trace; + cpu->current_state = initial_state; + cpu->state_trace = state_trace; + cpu->constraint = lmm_constraint_new(sys, cpu, cpu->current_power); -surf_host_resource_t surf_host_resource = NULL; + xbt_dict_set(cpu_set, name, cpu, NULL); + + return cpu; +} static void parse_file(const char *file) { + new_cpu("Cpu A", 200.0, 1.0, NULL, SURF_CPU_ON, NULL); + new_cpu("Cpu B", 100.0, 1.0, NULL, SURF_CPU_ON, NULL); } static void *name_service(const char *name) { - return NULL; + void *cpu=NULL; + + xbt_dict_get(cpu_set, name, &cpu); + + return cpu; +} + +static const char *get_resource_name(void *resource_id) +{ + return ((cpu_t) resource_id)->name; } static surf_action_t action_new(void *callback) @@ -43,6 +93,7 @@ static void action_recycle(surf_action_t action) static void action_change_state(surf_action_t action, e_surf_action_state_t state) { + surf_action_change_state(action, state); return; } @@ -56,33 +107,38 @@ static void solve(xbt_heap_float_t date) return; } -static void execute(void *host, xbt_maxmin_float_t size, surf_action_t action) +static surf_action_t execute(void *cpu, xbt_maxmin_float_t size) { + return NULL; } -static e_surf_host_state_t get_state(void *host) +static e_surf_cpu_state_t get_state(void *cpu) { - return SURF_HOST_OFF; + return SURF_CPU_OFF; } -surf_host_resource_t surf_host_resource_init(void) +surf_cpu_resource_t surf_cpu_resource_init(void) { - surf_host_resource = xbt_new0(s_surf_host_resource_t,1); - - surf_host_resource->resource.parse_file = parse_file; - surf_host_resource->resource.name_service = name_service; - surf_host_resource->resource.action_new=action_new; - surf_host_resource->resource.action_get_state=surf_action_get_state; - surf_host_resource->resource.action_free = action_free; - surf_host_resource->resource.action_cancel = action_cancel; - surf_host_resource->resource.action_recycle = action_recycle; - surf_host_resource->resource.action_change_state = action_change_state; - surf_host_resource->resource.share_resources = share_resources; - surf_host_resource->resource.solve = solve; - - surf_host_resource->execute = execute; - surf_host_resource->get_state = get_state; - - return surf_host_resource; + surf_cpu_resource = xbt_new0(s_surf_cpu_resource_t,1); + + surf_cpu_resource->resource.parse_file = parse_file; + surf_cpu_resource->resource.name_service = name_service; + surf_cpu_resource->resource.get_resource_name = get_resource_name; + surf_cpu_resource->resource.action_get_state=surf_action_get_state; + surf_cpu_resource->resource.action_free = action_free; + surf_cpu_resource->resource.action_cancel = action_cancel; + surf_cpu_resource->resource.action_recycle = action_recycle; + surf_cpu_resource->resource.action_change_state = action_change_state; + surf_cpu_resource->resource.share_resources = share_resources; + surf_cpu_resource->resource.solve = solve; + + surf_cpu_resource->execute = execute; + surf_cpu_resource->get_state = get_state; + + cpu_set = xbt_dict_new(); + + sys = lmm_system_new(); + + return surf_cpu_resource; } diff --git a/src/surf/cpu_private.h b/src/surf/cpu_private.h index f5ee3c304d..7315b42630 100644 --- a/src/surf/cpu_private.h +++ b/src/surf/cpu_private.h @@ -3,17 +3,17 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU LGPL) which comes with this package. */ -#ifndef _SURF_HOST_PRIVATE_H -#define _SURF_HOST_PRIVATE_H +#ifndef _SURF_CPU_PRIVATE_H +#define _SURF_CPU_PRIVATE_H #include "surf/surf.h" #include "surf/surf_private.h" -typedef struct surf_action_host { +typedef struct surf_action_cpu { s_surf_action_t generic_action; lmm_variable_t variable; -} s_surf_action_host_t, *surf_action_host_t; +} s_surf_action_cpu_t, *surf_action_cpu_t; -surf_host_resource_t surf_host_resource_init(void); +surf_cpu_resource_t surf_cpu_resource_init(void); #endif /* _SURF_SURF_PRIVATE_H */ diff --git a/src/surf/surf.c b/src/surf/surf.c index bc0667da7e..8783348814 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -4,7 +4,7 @@ under the terms of the license (GNU LGPL) which comes with this package. */ #include "surf_private.h" -#include "host_private.h" +#include "cpu_private.h" s_surf_global_t surf_global; @@ -46,7 +46,7 @@ void surf_action_change_state(surf_action_t action, e_surf_action_state_t state) void surf_init(void) { - surf_host_resource = surf_host_resource_init(); + surf_cpu_resource = surf_cpu_resource_init(); } /* xbt_heap_float_t surf_solve(void) */ diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index c22887c4f2..3be6b80779 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -9,7 +9,7 @@ #include "surf/surf.h" #include "surf/maxmin.h" #include "surf/trace_mgr.h" -#include "host_private.h" +#include "cpu_private.h" /* Generic functions common to all ressources */ e_surf_action_state_t surf_action_get_state(surf_action_t action); diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index cf25ec85ee..e49653fc1f 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -29,7 +29,7 @@ RL_tests = \ gras/datadesc_usage SG_tests = \ - surf/maxmin_usage surf/trace_usage + surf/maxmin_usage surf/trace_usage surf/surf_usage check_PROGRAMS = $(xbt_tests) $(RL_tests) $(SG_tests) check_SCRIPTS = run_tests gras/trp_tcp_usage @@ -63,6 +63,7 @@ xbt_heap_bench_LDADD= $(LDADD_UTILS) surf_maxmin_usage_LDADD= $(LDADD_UTILS) surf_trace_usage_LDADD= $(LDADD_UTILS) +surf_surf_usage_LDADD= $(LDADD_UTILS) gras_trp_tcp_client_LDADD= $(LDADD_RL) gras_trp_tcp_server_LDADD= $(LDADD_RL) -- 2.20.1