summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhh1 <hh1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2004-12-06 17:59:26 +0000
committerhh1 <hh1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2004-12-06 17:59:26 +0000
commit815f16c3655ac72327c972ed20ec00cc1ca5c97a (patch)
tree470168fe42a497788b892b3864a425a1bd8077f2
parente621f09e6d3eed00b1b81769a110ccea9d182a40 (diff)
downloadATCD-815f16c3655ac72327c972ed20ec00cc1ca5c97a.tar.gz
*** empty log message ***
-rw-r--r--examples/Group_Schedule/Group_Schedule.mwc3
-rw-r--r--examples/Group_Schedule/README61
-rw-r--r--examples/Group_Schedule/lib/SchedGroup.cpp168
-rw-r--r--examples/Group_Schedule/lib/SchedGroup.h137
-rw-r--r--examples/Group_Schedule/lib/SchedGroup.inl22
-rw-r--r--examples/Group_Schedule/simple/scenarioa.cpp116
-rw-r--r--examples/Group_Schedule/simple/scenarioa.mpc21
-rw-r--r--examples/Group_Schedule/simple/scenarioa.ns10
-rw-r--r--examples/Group_Schedule/simple/scenarioa_enable.dsui7
9 files changed, 545 insertions, 0 deletions
diff --git a/examples/Group_Schedule/Group_Schedule.mwc b/examples/Group_Schedule/Group_Schedule.mwc
new file mode 100644
index 00000000000..8f2ee7398f7
--- /dev/null
+++ b/examples/Group_Schedule/Group_Schedule.mwc
@@ -0,0 +1,3 @@
+workspace {
+}
+
diff --git a/examples/Group_Schedule/README b/examples/Group_Schedule/README
new file mode 100644
index 00000000000..958a78f292b
--- /dev/null
+++ b/examples/Group_Schedule/README
@@ -0,0 +1,61 @@
+
+
+INTRODUCTION
+
+This directory contains the C++ wrapper facade for using
+group scheduling library developed by University of
+Kansas as well as a simple example to demonstrate how
+to use the wrapper facade.
+
+For more information about group scheduling, please see the
+following references.
+
+Michael Frisbie, Douglas Niehaus, Venkita Subramonian and Christopher
+Gill, Group Scheduling in Systems Software
+<http://csdl.computer.org/comp/proceedings/ipdps/2004/2132/03/213230120aabs.htm>,
+Workshop on Parallel and Distributed Real-Time Systems 2004 (WPDRTS04),
+April 26th and 27th, 2004, Santa Fe, New Mexico.
+
+Tejasvi Aswathanarayana, Venkita Subramonian, Douglas Niehaus,
+Christopher Gill, Design and Performance of Configurable Endsystem
+Scheduling Mechanisms,
+<http://www.cse.seas.wustl.edu/techreportfiles/getreport.asp?395> IEEE
+RTAS 2005.
+
+
+Notice : The group scheduling library only works on
+ LINUX.
+
+SETUP
+
+1. In current stage, KUSP is required to compile the programs
+ in this directory. You can obtain KUSP from
+ http://kusp.ittc.ku.edu/archive/kusp.tar.gz.
+
+2. Uncompress the file downloaded.
+ tar zxvf kusp.tar.gz
+
+3. Follow the instruction in the README file from KUSP package
+ to install the LINUX kernel.
+
+4. Set the environment variable KUSP to the directory that
+ contains the KUSP tree.
+ e.g. export KUSP=~/kusp
+
+5. cd $KUSP/src/group_scheduling; make
+
+6. Generate Makefiles using MPC and make the targets.
+ cd $ACE_ROOT/examples/Group_Schedule
+ $ACE_ROOT/bin/mwc.pl
+ make
+
+How TO RUN THE SIMPLE EXAMPLE
+
+1. Start the group scheduling server
+ $KUSP/src/group_scheduling/libgroupsched/middleware/group_server
+
+2. Run the senarioa program
+ $ACE_ROOT/examples/Group_Schedule/simple/scenarioa
+
+
+ \ No newline at end of file
diff --git a/examples/Group_Schedule/lib/SchedGroup.cpp b/examples/Group_Schedule/lib/SchedGroup.cpp
new file mode 100644
index 00000000000..c7582b4badc
--- /dev/null
+++ b/examples/Group_Schedule/lib/SchedGroup.cpp
@@ -0,0 +1,168 @@
+// $Id$
+#include "SchedGroup.h"
+
+extern "C" {
+#include "include/middleware/group_sched_api.h"
+#include "include/middleware/group_sched_shared.h"
+#include "include/group_sched/group_sched_rr_abi.h"
+#include "include/group_sched/group_sched_static_priority_abi.h"
+#include "include/group_sched/group_sched_seq_abi.h"
+#include "include/group_sched/group_sched_frame_progress_abi.h"
+}
+
+#include <pthread.h>
+
+namespace {
+ int fd;
+ pthread_once_t once_control = PTHREAD_ONCE_INIT;
+
+ void init_group()
+ {
+ attach_shared_mem();
+ fd = grp_open();
+ }
+
+ struct SharedMemoryDettacher
+ {
+ ~SharedMemoryDettacher() {
+ detach_shared_mem();
+ }
+ } dettacher;
+}
+
+FrameProgressQoS::FrameProgressQoS()
+{
+ scheduler_name_ = FRAME_PROGRESS_SCHEDULER;
+ param_len_ = sizeof(int);
+ param_ = &progress;
+}
+
+RR_QoS::RR_QoS()
+{
+ scheduler_name_ = RR_SCHEDULER;
+ param_len_ = 0;
+ param_ = 0;
+}
+
+RR2_QoS::RR2_QoS()
+{
+ scheduler_name_ = RR2_SCHEDULER;
+ param_len_ = sizeof(sched_rr2_data);
+ param_ = static_cast<sched_rr2_data*>(this);
+}
+
+Seq_QoS::Seq_QoS()
+{
+ scheduler_name_ = SEQ_SCHEDULER;
+ param_len_ = 0;
+ param_ = 0;
+}
+
+Static_Priority_QoS::Static_Priority_QoS()
+{
+ scheduler_name_ = STATIC_PRIORITY_SCHEDULER;
+ param_len_ = sizeof(int);
+ param_ = &priority;
+}
+
+
+SchedGroup::SchedGroup(const char* name,
+ const SchedQoS& qos)
+: parent_name_(0)
+{
+ pthread_once(&once_control, init_group);
+ name_ = new char[strlen(name)+1];
+ strcpy(name_, name);
+ id_ = grp_create_group(fd, name_, qos.scheduler_name_, 0);
+ if (id_ != -1) {
+ grp_set_named_group_parameters(fd,
+ (char*)name_,
+ (void*)qos.param_,
+ qos.param_len_);
+ }
+}
+
+SchedGroup::SchedGroup(const char* name)
+: id_ (-1),parent_name_(0)
+{
+ //pthread_once(&once_control, init_group);
+ name_ = new char[strlen(name)+1];
+ strcpy(name_, name);
+}
+
+SchedGroup::~SchedGroup()
+{
+ if (parent_name_) {
+ if (parent_name_[0] == 0) {
+ grp_remove_topsdf_group(fd);
+ }
+ else {
+ grp_leave_group_by_name(fd, (char*)parent_name_, id_);
+ }
+ }
+ if (id_ != -1) {
+ grp_destroy_named_group(fd, (char*)name_);
+ }
+ delete name_;
+}
+
+int
+SchedGroup::set_as_top()
+{
+ if (fd == 0) return -1;
+ parent_name_ = "";
+ return grp_set_topsdf_group_by_name(fd, (char*)name_);
+}
+
+int
+SchedGroup::add_member(SchedGroup& member)
+{
+ if (fd == 0) return -1;
+ int ret = grp_join_group_by_name(fd,
+ (char*)name_,
+ (char*)member.name_,
+ GRP_COMP_TYPE_GROUP,
+ member.id_);
+ if (ret != -1)
+ member.parent_name_ = name_;
+ return ret;
+}
+
+int
+SchedGroup::add_current_thread(const SchedQoS& qos,
+ const char* thread_name)
+{
+ if (fd == 0) return -1;
+ member_id_t member_id = grp_join_group_by_name(fd,
+ (char*)name_,
+ (char*)thread_name,
+ GRP_COMP_TYPE_PROCESS,
+ ::getpid() );
+ if ( (int)member_id == -1)
+ return -1;
+ if (qos.param_len_ > 0)
+ {
+ if (grp_set_named_group_member_parameters(
+ fd, (char*)name_, (char*)thread_name, (void*)qos.param_, qos.param_len_
+ ) == -1)
+ return -1;
+ }
+ return member_id;
+}
+
+
+int
+SchedGroup::remove_current_thread(int member_id)
+{
+ if (fd == 0) return -1;
+ return grp_leave_group_by_name(fd, (char*)name_, member_id);
+}
+
+
+
+
+
+
+
+
+
diff --git a/examples/Group_Schedule/lib/SchedGroup.h b/examples/Group_Schedule/lib/SchedGroup.h
new file mode 100644
index 00000000000..1f130b8bc40
--- /dev/null
+++ b/examples/Group_Schedule/lib/SchedGroup.h
@@ -0,0 +1,137 @@
+// -*- C++ -*-
+
+//==========================================================================
+/**
+ * @file SchedGroup.h
+ *
+ * $Id$
+ *
+ * @author Huang-Ming Huang <hh1@cse.wustl.edu>
+ */
+//==========================================================================
+
+
+#ifndef SCHEDGROUP_H
+#define SCHEDGROUP_H
+#include <time.h>
+#include <sys/types.h>
+
+extern "C" {
+#include "include/group_sched/group_sched_rr2_abi.h"
+#include "include/middleware/group_sched_api.h"
+}
+
+class SchedGroup;
+
+class SchedQoS
+{
+protected:
+ const char* scheduler_name_;
+ int param_len_;
+ void* param_;
+ friend class SchedGroup;
+};
+
+class FrameProgressQoS : public SchedQoS
+{
+public:
+ FrameProgressQoS();
+ int progress;
+};
+
+class RR_QoS : public SchedQoS
+{
+public:
+ RR_QoS();
+};
+
+class RR2_QoS : public SchedQoS, public sched_rr2_data
+{
+public:
+ RR2_QoS();
+};
+
+class Seq_QoS : public SchedQoS
+{
+public:
+ Seq_QoS();
+};
+
+class Static_Priority_QoS : public SchedQoS
+{
+public:
+ Static_Priority_QoS();
+ int priority;
+};
+
+
+class SchedThread
+{
+public:
+ /**
+ * Set up the current thread to join the scheduling group \c grp. The thread
+ * will be removed from the group upon the destruction of the SchedThread object.
+ *
+ * If the thread cannot join the scheduling group, \c is_valid() will return false.
+ *
+ * @param grp The scheduling group that the current running thread joins.
+ * @param qos The QoS value for the thread.
+ * @param thread_name The name of the thread.
+ */
+ SchedThread(SchedGroup* grp, const SchedQoS& qos, const char* thread_name);
+ ~SchedThread();
+
+ /**
+ * Returns true if the current thread has joined to a scheduling group.
+ */
+ bool is_valid() const;
+private:
+ SchedThread(const SchedThread&);
+ SchedThread& operator = (const SchedThread&);
+ SchedGroup* grp_;
+ int member_id_;
+};
+
+class SchedGroup
+{
+public:
+ /**
+ * Create a new Scheduling Group.
+ */
+ SchedGroup(const char* name,
+ const SchedQoS& qos);
+ /**
+ * Contruct a SchedGroup object that represents
+ * an existing Scheduling Group with specified name.
+ */
+ SchedGroup(const char* name);
+ ~SchedGroup();
+
+ /**
+ * Sets the group as the top level scheduling group.
+ *
+ * @return -1 if unsuccessful.
+ */
+ int set_as_top();
+
+ /**
+ * Adds the new scheduling group \c member as a member of the scheduling group.
+ *
+ * @return -1 if unsuccessful.
+ */
+ int add_member(SchedGroup& member);
+
+private:
+ friend class SchedThread;
+ int add_current_thread(const SchedQoS& qos, const char* thread_name);
+ int remove_current_thread(int member_id);
+ SchedGroup(const SchedGroup&);
+ SchedGroup& operator = (const SchedGroup&);
+ char* name_;
+ int id_;
+ const char* parent_name_;
+};
+
+#include "SchedGroup.inl"
+
+#endif
diff --git a/examples/Group_Schedule/lib/SchedGroup.inl b/examples/Group_Schedule/lib/SchedGroup.inl
new file mode 100644
index 00000000000..51dcffb3170
--- /dev/null
+++ b/examples/Group_Schedule/lib/SchedGroup.inl
@@ -0,0 +1,22 @@
+// $Id$
+
+inline
+SchedThread::SchedThread(
+ SchedGroup* grp, const SchedQoS& qos, const char* thread_name)
+: grp_(grp)
+, member_id_(grp->add_current_thread(qos, thread_name))
+{
+}
+
+inline
+SchedThread::~SchedThread()
+{
+ if (member_id_ != -1)
+ grp_->remove_current_thread(member_id_);
+}
+
+inline bool
+SchedThread::is_valid() const
+{
+ return member_id_ != -1;
+}
diff --git a/examples/Group_Schedule/simple/scenarioa.cpp b/examples/Group_Schedule/simple/scenarioa.cpp
new file mode 100644
index 00000000000..afda564e117
--- /dev/null
+++ b/examples/Group_Schedule/simple/scenarioa.cpp
@@ -0,0 +1,116 @@
+// $Id$
+
+/*
+ * University of Kansas Center for Research, Inc. This software was
+ * developed by the Information and Telecommunication Technology
+ * Center (ITTC) at the University of Kansas. This software may be
+ * used and distributed according to the terms of the GNU Public
+ * License, incorporated herein by reference. ITTC does accept any
+ * liability whatsoever for this product.
+ *
+ * This project was developed under the direction of Dr. Douglas Niehaus.
+ *
+ */
+
+#define CONFIG_DSTREAM_SCENARIOA
+#include <dsui.h>
+#include "scenarioa_dsui_table.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <errno.h>
+#include <signal.h>
+#include <pthread.h>
+
+extern "C" {
+#include "include/middleware/group_sched_shared.h"
+}
+#include "SchedGroup.h"
+
+
+void my_sleep(int secs){
+ char block_state;
+
+ block_state = get_process_block_state(getpid());
+ controlled_task_may_block();
+ /* This task is going to sleep */
+ sleep(secs);
+ DSTRM_EVENT(SCENARIOA_FAM, AFTER_UNBLOCK, getpid(), 0, NULL);
+ controlled_task_unblocked();
+}
+
+
+void child_process(SchedGroup& grp, const char* process_name)
+{
+ DSTRM_EVENT(SCENARIOA_FAM, JOINING_GROUP, getpid(), 0, NULL);
+ Seq_QoS qos;
+ SchedThread thr_member(&grp, qos, process_name);
+
+ if(!thr_member.is_valid()){
+ printf("Error! in join_grp\n");
+ return;
+ }
+
+
+ for (int k = 0; k < 3; ++k) {
+ DSTRM_EVENT(SCENARIOA_FAM,IN_WHILE_LOOP, getpid(), 0, NULL);
+ int j;
+ for(int i=0; i<100000; i++)
+ j++;
+
+ DSTRM_EVENT(SCENARIOA_FAM, CALLING_SLEEP, getpid(), 0, NULL);
+ my_sleep(2);
+ DSTRM_EVENT(SCENARIOA_FAM, AFTER_SLEEP, getpid(), 0, NULL);
+ }
+
+ DSTRM_EVENT(SCENARIOA_FAM, EXITING, getpid(), 0, NULL);
+ return;
+}
+
+extern void init_group();
+
+int main(int argc, char **argv){
+ int pid=0, num_processes=0;
+
+ if(argc!=3){
+ printf("usage\n");
+ printf("scenarioa <name of process> <number of processes>\n");
+ exit(0);
+ }
+
+ num_processes=atoi(argv[2]);
+
+ Seq_QoS qos;
+
+ SchedGroup top_group("SS", qos);
+
+ if (top_group.set_as_top() == -1) {
+ fprintf (stderr, "Error in setting top group\n");
+ exit(1);
+ }
+
+
+ DSUI_INIT("scenarioa", "scenarioa_enable.dsui");
+
+ for(int i=0;i<num_processes;i++) {
+ char process_name[100];
+
+ DSTRM_EVENT(SCENARIOA_FAM, CREATING_THREAD, getpid(), 0, NULL);
+ pid=fork();
+ sprintf(process_name,"%s%d", "THREAD",i);
+
+ if(pid==0){
+ child_process(top_group, process_name);
+ exit(0);
+ }
+ }
+
+ /* Make the main thread sleep for 10 secs */
+ sleep(10);
+ DSTRM_EVENT(SCENARIOA_FAM, EXITING, getpid(), 0, NULL);
+
+ return 0;
+}
diff --git a/examples/Group_Schedule/simple/scenarioa.mpc b/examples/Group_Schedule/simple/scenarioa.mpc
new file mode 100644
index 00000000000..fd2812e26bc
--- /dev/null
+++ b/examples/Group_Schedule/simple/scenarioa.mpc
@@ -0,0 +1,21 @@
+project(Scenarioa) {
+ exename = scenarioa
+ includes += $(KUSP)/src/datastreams/dsui/libdsui $(KUSP)/src/datastreams/shared/include $(KUSP)/src/group_scheduling/libgroupsched/middleware ../lib
+ libpaths += $(KUSP)/src/group_scheduling/libgroupsched/middleware/libs ../lib
+ lit_libs += groupschedmiddlewareclient dsui
+ libs += GrpSchedWrapper
+ macros += CONFIG_DSUI
+
+ Define_Custom(DSUI) {
+ automatic = 0
+ command = $(KUSP)/src/datastreams/dsui/utils/dsui-parse.py
+ commandflags = -z $(KUSP)/src/datastreams/shared/utils/dstream_admin.ns -t scenarioa -n
+ inputext = .ns
+ pre_extension = _dsui_table , _dsui_families , _dsui_vars
+ header_outputext = .h
+ }
+
+ DSUI_Files {
+ scenarioa.ns
+ }
+}
diff --git a/examples/Group_Schedule/simple/scenarioa.ns b/examples/Group_Schedule/simple/scenarioa.ns
new file mode 100644
index 00000000000..635044a4804
--- /dev/null
+++ b/examples/Group_Schedule/simple/scenarioa.ns
@@ -0,0 +1,10 @@
+DSTRM_FAMILY SCENARIOA 6 "Scenario A family"
+
+
+DSTRM_EVENT SCENARIOA 6 CREATING_THREAD 0 " " print_string
+DSTRM_EVENT SCENARIOA 6 IN_WHILE_LOOP 1 " " print_string
+DSTRM_EVENT SCENARIOA 6 CALLING_SLEEP 2 " " print_string
+DSTRM_EVENT SCENARIOA 6 EXITING 3 " " print_string
+DSTRM_EVENT SCENARIOA 6 JOINING_GROUP 4 " " print_string
+DSTRM_EVENT SCENARIOA 6 AFTER_SLEEP 5 " " print_string
+DSTRM_EVENT SCENARIOA 6 AFTER_UNBLOCK 6 " " print_string
diff --git a/examples/Group_Schedule/simple/scenarioa_enable.dsui b/examples/Group_Schedule/simple/scenarioa_enable.dsui
new file mode 100644
index 00000000000..c2320d27035
--- /dev/null
+++ b/examples/Group_Schedule/simple/scenarioa_enable.dsui
@@ -0,0 +1,7 @@
+DSTRM_EVENT SCENARIOA 6 CREATING_THREAD 0
+DSTRM_EVENT SCENARIOA 6 IN_WHILE_LOOP 1
+DSTRM_EVENT SCENARIOA 6 CALLING_SLEEP 2
+DSTRM_EVENT SCENARIOA 6 EXITING 3
+DSTRM_EVENT SCENARIOA 6 JOINING_GROUP 4
+DSTRM_EVENT SCENARIOA 6 AFTER_SLEEP 5
+DSTRM_EVENT SCENARIOA 6 UNBLOCK 6