On Wed, 2014-12-03 at 17:52 +0800, Pi-Cheng Chen wrote:
> On 3 December 2014 at 17:24, Ivan T. Ivanov <iiva...@mm-sol.com> wrote:
> > On Wed, 2014-12-03 at 15:08 +0800, Pi-Cheng Chen wrote:
> > > On 2 December 2014 at 19:04, Vincent Guittot guit...@linaro.org> wrote:
> > > > On 2 December 2014 at 08:21, pi-cheng.chen c...@linaro.org> wrote:
> > > > > Add 2 new kind of event for running a memory or a io bounded load.
> > > > > "mem" name for a load is memory bounded, and "iorun" name for a load 
> > > > > is io
> > > > > bounded. The default file to be written to create the load is 
> > > > > /dev/null and
> > > > > the device/file could be specified with "io_device" key in "global" 
> > > > > section.
> > > > 
> > > > Hi pi-cheng
> > > > 
> > > > What's the unit of the mem and iorun ?
> > > > As an example, "mem" : 2000 will do a copy of 2000 Bytes ? KBytes ?
> > > > 
> > > Hi Vincent,
> > > 
> > > Thanks for reviewing.
> > > The unit of mem and iorun here is the size to be copied/written in byte.
> > > As an example, "mem" : 2000 will do a 2000 bytes copy.
> > > 
> > > > > E.g.
> > > > > "tasks" : {
> > > > > "thread0" :
> > > > > { "sleep" : 1000, "run" : 100, "mem" : 1000, "sleep" 10000, "iorun" : 
> > > > > 1000 }
> > > > > },
> > > > > "global" : { "io_device" : "/dev/ttyS0" }
> > > > > 
> > > > > Signed-off-by: pi-cheng.chen c...@linaro.org>
> > > > > ---
> > > > >  src/rt-app.c              | 74 
> > > > > +++++++++++++++++++++++++++++++++++++++++++++++
> > > > >  src/rt-app.h              |  2 ++
> > > > >  src/rt-app_parse_config.c | 23 +++++++++++++++
> > > > >  src/rt-app_types.h        |  4 +++
> > > > >  4 files changed, 103 insertions(+)
> > > > > 
> > > > > diff --git a/src/rt-app.c b/src/rt-app.c
> > > > > index 3cd601d..13f72e4 100644
> > > > > --- a/src/rt-app.c
> > > > > +++ b/src/rt-app.c
> > > > > @@ -33,6 +33,8 @@ static volatile int continue_running;
> > > > >  static pthread_t *threads;
> > > > >  static int nthreads;
> > > > >  static int p_load;
> > > > > +static char *buffer[2];
> > > > > +static int io_fd;
> > > > >  rtapp_options_t opts;
> > > > > 
> > > > >  static ftrace_data_t ft_data = {
> > > > > @@ -110,6 +112,45 @@ static inline loadwait(unsigned long exec)
> > > > >         return load_count;
> > > > >  }
> > > > > 
> > > > > +static void ioload(unsigned long count)
> > > > > +{
> > > > > +       ssize_t ret;
> > > > > +       char *buf = buffer[0];
> > > > > +
> > > > > +       while (count != 0) {
> > > > > +               ret = write(io_fd, buffer, count);
> > > > 
> > > > count can be higher than buffer size
> > > > 
> > > > so you have defined a MEM_BUFFER_SIZE for mem transfer but not for 
> > > > iorun ?
> > > > 
> > > 
> > > I forgot to do such check for iorun. Will do it.
> > > 
> > > > > +               if (ret == -1) {
> > > > > +                       perror("write");
> > > > > +                       return;
> > > > > +               }
> > > > > +               count -= ret;
> > > > > +               buf += ret;
> > > > > +       }
> > > > > +}
> > > > > +
> > > > > +static void memload(unsigned long count)
> > > > > +{
> > > > > +       static unsigned long current = 0;
> > > > > +
> > > > > +       while (count > 0) {
> > > > > +               unsigned long size;
> > > > > +
> > > > > +               if (count > MEM_BUFFER_SIZE)
> > > > > +                       size = MEM_BUFFER_SIZE;
> > > > > +               else
> > > > > +                       size = count;
> > > > > +
> > > > > +               if (size > (MEM_BUFFER_SIZE - current))
> > > > > +                       size = MEM_BUFFER_SIZE - current;
> > > > > +
> > > > > +               memcpy(buffer[0], buffer[1], size);
> > > > 
> > > > I wonder if a memset would be better
> > > > 
> > > 
> > > Sure. Will do it.
> > > 
> > > > > +               count -= size;
> > > > > +               current += size;
> > > > > +               if (current >= MEM_BUFFER_SIZE)
> > > > > +                       current -= MEM_BUFFER_SIZE;
> > > > 
> > > > The size of MEM_BUFFER_SIZE will deeply impact how we will trash the
> > > > cache and how the memory access (up to the ddr) will be the
> > > > bottleneck. This should be at least configurable in the global section
> > > > 
> > > 
> > > I was thinking is there a generic way the get the cache size of the CPU,
> > > but I failed to do so. So I just set it as a size bigger than the size of 
> > > cache
> > > on my laptop, which is 3MB. Yes I should make it configurable in the
> > > global section.
> > 
> > Ok, so buffer size could be specified in json file. But why there should
> > be limitation like MEM_BUFFER_SIZE, could we just leave buffer size decision
> > to user?
> > 
> Hi Ivan,
> 
> MEM_BUFFER_SIZE should be replaced with the buffer size specified in
> "global" section in JSON file in next version.
> The reason why we have this limitation here is to prevent buffer overflow
> from happening. IOW, the size of memory to be write in a event (specified with
> "mem" key) might be larger than the memory buffer allocated to create the
> load (will be specified in "global" section).

Hm, I will like to be able to define memory access size per mem object.
Something like attached patch.

> 
> > There is no guarantee that CPU will touch the buffers with memcpy.
> > It depends how memcpy is implemented. Could we use straight
> > buf1[x] = buf2[x] or something more fancy?
> > 
> 
> How do you think about memset suggested by Vincent?
> 

Yep.

Regards,
Ivan
From 25704d56f0649a3b2d3865199bd809a5169bc417 Mon Sep 17 00:00:00 2001
From: "Ivan T. Ivanov" <iiva...@mm-sol.com>
Date: Mon, 27 Oct 2014 15:56:15 +0200
Subject: [PATCH] add maccess event

Simulation of memory intensive task

Signed-off-by: Ivan T. Ivanov <iiva...@mm-sol.com>
---
 doc/examples/maccess.json | 22 ++++++++++++++++++++++
 src/rt-app.c              | 34 ++++++++++++++++++++++++++++++++++
 src/rt-app_parse_config.c | 14 ++++++++++++++
 src/rt-app_types.h        |  1 +
 4 files changed, 71 insertions(+)
 create mode 100644 doc/examples/maccess.json

diff --git a/doc/examples/maccess.json b/doc/examples/maccess.json
new file mode 100644
index 0000000..ac4123b
--- /dev/null
+++ b/doc/examples/maccess.json
@@ -0,0 +1,22 @@
+{
+	/*
+	 * Simple use case with 2 threads that runs for 10 ms and wake up each
+	 * other until the use case is stopped with Ctrl+C
+	 */
+	"tasks" : {
+		"thread0" : {
+			"loop" : -1,
+			"maccess" : 16384,
+			"resume" : "thread1",
+			"run" :     10000,
+			"suspend" : "thread0",
+		},
+		"thread1" : {
+			"loop" : -1,
+			"maccess" : 4096,
+			"resume" : "thread0",
+			"run" :     10000,
+			"suspend" : "thread1",
+		},
+	},
+}
diff --git a/src/rt-app.c b/src/rt-app.c
index de91ff1..013a44f 100644
--- a/src/rt-app.c
+++ b/src/rt-app.c
@@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #define _GNU_SOURCE
 #include <fcntl.h>
+#include <stdlib.h>
 #include "rt-app.h"
 #include "rt-app_utils.h"
 #include <sched.h>
@@ -110,6 +111,33 @@ static inline loadwait(unsigned long exec)
 	return load_count;
 }
 
+void memory_access(size_t size)
+{
+	int *src_buf;
+	int *dst_buf;
+	int i,j;
+
+	src_buf = malloc(size);
+	dst_buf = malloc(size);
+	if(!src_buf || !dst_buf) {
+		log_error("maccess can't allocate %d\n", size);
+		return;
+	}
+
+	/* Initialize buffers and transfer */
+	memset(dst_buf, 0, size);
+	for (j = 0; j < (size/4); j++) {
+		src_buf[j] = rand();
+	}
+
+	memcpy(dst_buf, src_buf, size);
+	if(memcmp(dst_buf, src_buf, size))
+		log_error("maccess mismatch between source and destination buffers\n");
+
+	free(src_buf);
+	free(dst_buf);
+}
+
 static int run_event(event_data_t *event, int dry_run,
 		unsigned long *perf, unsigned long *duration, rtapp_resource_t *resources)
 {
@@ -168,6 +196,12 @@ static int run_event(event_data_t *event, int dry_run,
 			*duration += timespec_to_usec(&t_end);
 		}
 		break;
+	case rtapp_maccess:
+		{
+		log_debug("maccess %d ", event->duration);
+		memory_access(event->duration);
+		break;
+		}
 	case rtapp_timer:
 		{
 			struct timespec t_period, t_now;
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c
index 63699e8..10d2e71 100644
--- a/src/rt-app_parse_config.c
+++ b/src/rt-app_parse_config.c
@@ -320,6 +320,18 @@ parse_thread_event_data(char *name, struct json_object *obj,
 		return;
 	}
 
+	if (!strncmp(name, "maccess", strlen("maccess"))) {
+
+		if (!json_object_is_type(obj, json_type_int))
+			goto unknown_event;
+
+		data->duration = json_object_get_int(obj);
+		data->type = rtapp_maccess;
+
+		log_info(PIN2 "type %d size %d", data->type, data->duration);
+		return;
+	}
+
 	if (!strncmp(name, "lock", strlen("lock")) ||
 			!strncmp(name, "unlock", strlen("unlock"))) {
 
@@ -493,6 +505,8 @@ obj_is_event(char *name)
 			return rtapp_suspend;
 	if (!strncmp(name, "resume", strlen("resume")))
 			return rtapp_resume;
+	if (!strncmp(name, "maccess", strlen("maccess")))
+			return rtapp_maccess;
 
 	return 0;
 }
diff --git a/src/rt-app_types.h b/src/rt-app_types.h
index fd29a06..243d5ce 100644
--- a/src/rt-app_types.h
+++ b/src/rt-app_types.h
@@ -65,6 +65,7 @@ typedef enum resource_t
 	rtapp_timer,
 	rtapp_suspend,
 	rtapp_resume,
+	rtapp_maccess,
 } resource_t;
 
 struct _rtapp_mutex {
-- 
1.9.1

_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to