Esempio n. 1
0
    def res_allocat(self, heart_rate):

        # get current cpu resource
        cur_bw = 0
        myinfo = self.shared_data[self.domuid]
        if self.rtxen_or_credit == "rtxen":
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['b'])
        elif self.rtxen_or_credit == "credit":
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['w'])

        # calculate next cpu resource assignment
        cur_bw = self.allocMod.exec_allocation(heart_rate, cur_bw)
        # run stride sharing if needed
        # (cur_bw,other_cur_bw)=self.allocMod.exec_stride_sharing(cur_bw,time.time())

        other_cur_bw = self.timeslice_us - cur_bw

        # assign the new cpu resource to VM
        other_info = self.shared_data[self.other_domuid]
        if self.rtxen_or_credit == "rtxen":
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = cur_bw
            xen_interface.sched_rtds(self.domuid, self.timeslice_us, cur_bw,
                                     [])
            xen_interface.sched_rtds(self.other_domuid, self.timeslice_us,
                                     other_cur_bw, [])
        elif self.rtxen_or_credit == "credit":
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = cur_bw
            xen_interface.sched_credit(self.domuid, cur_bw)
            xen_interface.sched_credit(self.other_domuid, other_cur_bw)

        # write data to data.txt for realtime_plot.py for visulization
        time_now = str(time.time())
        info = self.domuid + " " + str(heart_rate) + " hr " + time_now + "\n"
        place_holder_for_graph = " x x x x x "
        info += self.domuid + " " + str(
            cur_bw /
            self.timeslice_us) + place_holder_for_graph + time_now + "\n"
        info += self.other_domuid + " " + str(
            other_cur_bw /
            self.timeslice_us) + place_holder_for_graph + time_now
        with open("data.txt", "a") as myfile:
            myfile.write(info + "\n")
        return
Esempio n. 2
0
    def res_allocat(self, heart_rate):
        cur_bw = 0
        myinfo = self.shared_data[self.domuid]
        if self.rtxen_or_credit == "rtxen":
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['b'])
        elif self.rtxen_or_credit == "credit":
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['w'])

        cur_bw = self.allocMod.exec_allocation(heart_rate, cur_bw)
        other_cur_bw = self.timeslice_us - cur_bw
        # (cur_bw,other_cur_bw)=self.allocMod.exec_sharing(cur_bw)

        other_info = self.shared_data[self.other_domuid]
        if self.rtxen_or_credit == "rtxen":
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = cur_bw
            xen_interface.sched_rtds(self.domuid, self.timeslice_us, cur_bw,
                                     [])
            xen_interface.sched_rtds(self.other_domuid, self.timeslice_us,
                                     other_cur_bw, [])
        elif self.rtxen_or_credit == "credit":
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = cur_bw
            xen_interface.sched_credit(self.domuid, cur_bw)
            xen_interface.sched_credit(self.other_domuid, other_cur_bw)

        # buf=10000
        # self.shared_data['cnt'] = (self.shared_data['cnt']+1)%buf
        time_now = str(time.time())
        info = self.domuid + " " + str(heart_rate) + " hr " + time_now + "\n"
        place_holder_for_graph = " x x x x x "
        info += self.domuid + " " + str(
            cur_bw / self.timeslice_us) + place_holder_for_graph + time_now
        # info += self.other_domuid+ " "+str(other_cur_bw/self.timeslice_us) + place_holder_for_graph+time_now
        with open("data.txt", "a") as myfile:
            myfile.write(info + "\n")
        return
Esempio n. 3
0
    def vmonitor(self):  # one monitor observe one domU at a time
        with Client(unix_socket_path="/var/run/xenstored/socket_ro") as c:
            m = c.monitor()
            for key in self.keys:
                tmp_key_path = (self.base_path + '/' + self.domuid + '/' +
                                key).encode()
                token = (key).encode()
                m.watch(tmp_key_path, token)

            msg = ""
            while msg != 'done':
                path, token = next(m.wait())
                msg = c.read(path).decode()
                self.threadLock.acquire()
                if self.keys[1] in path.decode():
                    if msg.isdigit():
                        self.algo = int(msg)
                        with open("info.txt", "a") as myfile:
                            myfile.write(self.domuid + " " + (msg) + " " +
                                         str(time.time()) + "\n")
                if self.keys[2] in path.decode():
                    self.pid.reset()
                    if msg.isdigit():
                        with open("info.txt", "a") as myfile:
                            myfile.write(self.domuid + " " + (msg) +
                                         " frame freq" + " " +
                                         str(time.time()) + "\n")
                if self.keys[3] in path.decode():
                    self.pid.reset()
                    if msg.isdigit():
                        tmp_new_timeslice_us = int(msg) * 1000
                        if self.rtxen_or_credit == 1:
                            cur_bw = 0
                            myinfo = self.shared_data[self.domuid]
                            for vcpu in myinfo:
                                if vcpu['pcpu'] != -1:
                                    cur_bw = int(vcpu['b'])
                            xen_interface.sched_rtds(
                                self.domuid, tmp_new_timeslice_us, cur_bw /
                                self.timeslice_us * tmp_new_timeslice_us, [])
                            xen_interface.sched_rtds(
                                str(int(self.domuid) + 2),
                                tmp_new_timeslice_us,
                                (self.timeslice_us - cur_bw) /
                                self.timeslice_us * tmp_new_timeslice_us, [])

                            for vcpu in myinfo:
                                if vcpu['pcpu'] != -1:
                                    vcpu[
                                        'b'] = cur_bw / self.timeslice_us * tmp_new_timeslice_us
                                    vcpu['p'] = tmp_new_timeslice_us

                        else:
                            cur_bw = 0
                            myinfo = self.shared_data[self.domuid]
                            for vcpu in myinfo:
                                if vcpu['pcpu'] != -1:
                                    cur_bw = int(vcpu['w'])
                            xen_interface.sched_credit(
                                self.domuid, cur_bw / self.timeslice_us *
                                tmp_new_timeslice_us)
                            xen_interface.sched_credit(
                                str(int(self.domuid) + 2),
                                (self.timeslice_us - cur_bw) /
                                self.timeslice_us * tmp_new_timeslice_us)
                            for vcpu in myinfo:
                                if vcpu['pcpu'] != -1:
                                    vcpu[
                                        'w'] = cur_bw / self.timeslice_us * tmp_new_timeslice_us
                        xen_interface.sched_credit_timeslice(int(msg))
                        self.timeslice_us = tmp_new_timeslice_us
                        with open("info.txt", "a") as myfile:
                            myfile.write(self.domuid + " " + (msg) +
                                         " time slice len 6" + " " +
                                         str(time.time()) + "\n")

                if self.keys[0] in path.decode():
                    heart_rate = -1
                    try:
                        heart_rate = float(msg)
                    except:
                        heart_rate = -1
                    if heart_rate > -1:
                        self.res_allocat(heart_rate)
                        #self.res_allo(self.algo,self.rtxen_or_credit,float(msg),self.shared_data,self.domuid ,self.min_heart_rate,self.max_heart_rate)

                # try :
                # 	if self.keys[0] in path.decode():
                # 		self.res_allocat(float(msg))
                # 		#self.res_allo(self.algo,self.rtxen_or_credit,float(msg),self.shared_data,self.domuid ,self.min_heart_rate,self.max_heart_rate)
                # except:
                # 	#print("meow",int(self.domuid),token.decode(),msg)

                self.threadLock.release()
Esempio n. 4
0
    def res_allocat(self, heart_rate):

        minn = int(self.timeslice_us * 0.01)
        print(self.domuid, heart_rate, self.algo)

        # if int(self.domuid)>=3:
        # 	#print("dummy",int(self.domuid)-2,"heartrate:",heart_rate)
        # 	buf=50
        # 	self.shared_data['cnt'] = (self.shared_data['cnt']+1)%buf
        # 	info = self.domuid+" "+str(heart_rate)+" dummy is here"
        # 	if self.shared_data['cnt']%buf!=0:
        # 		with open("info.txt", "a") as myfile:
        # 			myfile.write(info+"\n")
        # 	else:
        # 		with open("info.txt", "w") as myfile:
        # 			myfile.write(info+"\n")

        # 	return

        # tab='               dom '+str(int(self.domuid))
        # if int(self.domuid)<2:
        # 	tab='dom '+str(int(self.domuid))
        # print(tab,'heart_rate',heart_rate)

        cur_bw = 0
        myinfo = self.shared_data[self.domuid]

        if self.rtxen_or_credit == 1:
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['b'])
        elif self.rtxen_or_credit == 0:
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['w'])

        if self.algo == 0:
            # static
            default_bw = int(self.timeslice_us / 2)  #dummy
            if cur_bw != default_bw:
                cur_bw = default_bw
            cur_bw = int(self.timeslice_us * args["static_alloc"] / 100)
        if self.algo == 1:
            # amid
            alpha = 1
            beta = .9
            free = self.timeslice_us - cur_bw

            if (heart_rate < self.mid):
                if cur_bw < self.timeslice_us - minn:
                    free = free * beta
                    cur_bw = self.timeslice_us - free
                else:
                    cur_bw = self.timeslice_us - minn
            if (heart_rate > self.mid):
                if cur_bw > minn:
                    free += alpha * minn
                    cur_bw = self.timeslice_us - free
            cur_bw = int(cur_bw)  #-int(cur_bw)%100
        if self.algo == 2:
            # 99%
            default_bw = int(self.timeslice_us - minn)  #dummy
            if cur_bw != default_bw:
                cur_bw = default_bw
            cur_bw = int(cur_bw)  #-int(cur_bw)%100
        if self.algo == 3:
            # apid algo
            output = self.pid.update(heart_rate)
            # output+=self.timeslice_us/2
            if self.pid.start > 0:
                tmp_cur_bw = output + cur_bw  #int(output*cur_bw+cur_bw)-int(output*cur_bw+cur_bw)%100
                if tmp_cur_bw >= self.timeslice_us - minn:  #dummy
                    cur_bw = self.timeslice_us - minn
                elif tmp_cur_bw <= minn:  #self.timeslice_us/3:
                    cur_bw = minn  #int(self.timeslice_us/3)
                else:
                    cur_bw = tmp_cur_bw

            cur_bw = int(cur_bw)  #-int(cur_bw)%100

        else:
            self.pid.reset()
        if self.algo == 4:
            # aimd algo_range
            alpha = 3.5
            beta = .95
            free = self.timeslice_us - cur_bw
            if (heart_rate < self.min_heart_rate):
                if cur_bw < self.timeslice_us - minn:
                    free = free * beta
                    cur_bw = self.timeslice_us - free
                else:
                    cur_bw = self.timeslice_us - minn
            if (heart_rate > self.max_heart_rate):
                if cur_bw > minn:
                    free += alpha * minn
                    cur_bw = self.timeslice_us - free
            cur_bw = int(cur_bw)  #-int(cur_bw)%100
            # print("      ",cur_bw)
        if self.algo == 5:
            # limd
            beta = .9
            free = self.timeslice_us - cur_bw
            if (heart_rate < self.min_heart_rate):
                if cur_bw < self.timeslice_us - minn:
                    free = free * beta
                    cur_bw = self.timeslice_us - free
            if (heart_rate > self.max_heart_rate):
                if cur_bw > minn:
                    cur_bw -= minn
            if heart_rate > self.max_heart_rate:
                self.target_reached_cnt += 1
                if self.target_reached_cnt == 16:
                    self.target_reached_cnt -= 8
                    if cur_bw > minn:
                        cur_bw -= minn
            else:
                self.target_reached_cnt = 0

        other_cur_bw = self.timeslice_us - cur_bw
        other_info = self.shared_data[self.other_domuid]
        cur_bw = cur_bw
        myinfo = self.shared_data[self.domuid]

        if self.rtxen_or_credit == 1:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = cur_bw
            xen_interface.sched_rtds(self.domuid, self.timeslice_us, cur_bw,
                                     [])
            if args["RTdomUs_Dummy"] != None:
                xen_interface.sched_rtds(self.other_domuid, self.timeslice_us,
                                         other_cur_bw, [])

        elif self.rtxen_or_credit == 0:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = cur_bw
            xen_interface.sched_credit(self.domuid, cur_bw)
            if args["CreditdomUs_Dummy"] != None:
                xen_interface.sched_credit(self.other_domuid, other_cur_bw)

        buf = 10000
        self.shared_data['cnt'] = (self.shared_data['cnt'] + 1) % buf
        time_now = str(time.time())
        info = self.domuid + " " + str(heart_rate) + " hr " + time_now + "\n"
        info += self.domuid + " " + str(
            cur_bw /
            self.timeslice_us) + " cpu1 cpu2 cpu3 cpu4 cpu5 " + time_now + "\n"
        with open("info.txt", "a") as myfile:
            myfile.write(info + "\n")

        return
Esempio n. 5
0
        return

    # https://xenbits.xen.org/docs/unstable/man/xl.1.html#SCHEDULER-SUBCOMMANDS
    # cpupool, vcpupin, rtds-budget,period, extratime, vcpu-list


threadLock = threading.Lock()
threads = []
shared_data = xen_interface.get_global_info()

xen_interface.sched_credit(args["CreditdomUs"],
                           timeslice_us * args["static_alloc"] / 100)
xen_interface.sched_credit(args["CreditdomUs_Dummy"],
                           timeslice_us * (1 - args["static_alloc"] / 100))
xen_interface.sched_rtds(args["RTdomUs"], timeslice_us,
                         timeslice_us * args["static_alloc"] / 100, [])
xen_interface.sched_rtds(args["RTdomUs_Dummy"], timeslice_us,
                         timeslice_us * (1 - args["static_alloc"] / 100), [])

# if '1' in shared_data['rtxen']:
# 	xen_interface.sched_rtds(1,timeslice_us,default_bw,[])
# 	xen_interface.sched_rtds(2,timeslice_us,timeslice_us-default_bw,[])
# if '1' in shared_data['xen']:
# 	xen_interface.sched_credit(1,default_bw)
# 	xen_interface.sched_credit(2,timeslice_us-default_bw)

# for i,domuid in enumerate(shared_data['rtxen']):
# 	xen_interface.sched_rtds(domuid,timeslice_us,default_bw,[])
# 	xen_interface.sched_rtds(str(int(domuid)+2),timeslice_us,timeslice_us-default_bw,[])

# for domuid in shared_data['xen']:
Esempio n. 6
0
        info += self.domuid + " " + str(
            cur_bw /
            self.timeslice_us) + place_holder_for_graph + time_now + "\n"
        # info += self.other_domuid+ " "+str(other_cur_bw/self.timeslice_us) + place_holder_for_graph+time_now
        with open("data.txt", "a") as myfile:
            myfile.write(info + "\n")
        return


# initializing data and setup inital cpu assignment
threadLock = threading.Lock()
threads = []
shared_data = xen_interface.get_global_info()
for domuid in monitoring_domU:
    if domuid in shared_data['rtxen']:
        xen_interface.sched_rtds(domuid, timeslice_us,
                                 timeslice_us * args["static_alloc"] / 100, [])
    if domuid in shared_data['credit']:
        xen_interface.sched_credit(domuid, timeslice_us / 2)

# initializing values
shared_data = xen_interface.get_global_info()

pp = pprint.PrettyPrinter(indent=2)
pp.pprint(shared_data)

# stdout ready status to inform user
print('')
print('Single VM mode')
print('monitoring:')
for i in range(len(monitoring_domU)):
    vmstr = 'VM' + str(i + 1)
Esempio n. 7
0
        info = self.domuid + " " + str(heart_rate) + " hr " + time_now + "\n"
        place_holder_for_graph = " x x x x x "
        info += self.domuid + " " + str(
            cur_bw / self.timeslice_us) + place_holder_for_graph + time_now
        with open("data.txt", "a") as myfile:
            myfile.write(info + "\n")
        return


# initializing data and setup inital cpu assignment
threadLock = threading.Lock()
threads = []
shared_data = xen_interface.get_global_info()
for i in range(len(monitoring_domU)):
    if monitoring_domU[i] in shared_data['rtxen']:
        xen_interface.sched_rtds(monitoring_domU[i], timeslice_us,
                                 timeslice_us / 2, [])
        xen_interface.sched_rtds(dummy_domU[i], timeslice_us, timeslice_us / 2,
                                 [])
    if monitoring_domU[i] in shared_data['credit']:
        xen_interface.sched_credit(monitoring_domU[i], timeslice_us / 2)
        xen_interface.sched_credit(dummy_domU[i], timeslice_us / 2)

# stdout ready status to inform user
shared_data = xen_interface.get_global_info()
pp = pprint.PrettyPrinter(indent=2)
pp.pprint(shared_data)
print('')
print('Experiment 1: RT-Xen vs Credit')
print('monitoring:')
for i in range(2):
    vmstr = 'VM' + str(i + 1)
Esempio n. 8
0
    def res_allocat(self, heart_rate):

        # print(self.domuid, heart_rate, self.algo)

        # if int(self.domuid)>=3:
        # 	#print("dummy",int(self.domuid)-2,"heartrate:",heart_rate)
        # 	buf=50
        # 	self.shared_data['cnt'] = (self.shared_data['cnt']+1)%buf
        # 	info = self.domuid+" "+str(heart_rate)+" dummy is here"
        # 	if self.shared_data['cnt']%buf!=0:
        # 		with open("info.txt", "a") as myfile:
        # 			myfile.write(info+"\n")
        # 	else:
        # 		with open("info.txt", "w") as myfile:
        # 			myfile.write(info+"\n")

        # 	return

        # tab='               dom '+str(int(self.domuid))
        # if int(self.domuid)<2:
        # 	tab='dom '+str(int(self.domuid))
        # print(tab,'heart_rate',heart_rate)

        cur_bw = 0
        myinfo = self.shared_data[self.domuid]

        if self.rtxen_or_credit == 1:
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['b'])
        elif self.rtxen_or_credit == 0:
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['w'])

        cur_bw = self.allocMod.exec_allocation(heart_rate, cur_bw)

        (cur_bw, other_cur_bw) = self.allocMod.exec_sharing(cur_bw)

        if False:
            other_cur_bw = 0
            other_info = self.shared_data[self.other_domuid]
            myinfo = self.shared_data[self.domuid]

            if self.rtxen_or_credit == 1:
                for vcpu in other_info:
                    if vcpu['pcpu'] != -1:
                        other_cur_bw = vcpu['b']

            elif self.rtxen_or_credit == 0:
                for vcpu in other_info:
                    if vcpu['pcpu'] != -1:
                        other_cur_bw = vcpu['w']

            if cur_bw + other_cur_bw > self.timeslice_us:

                my_pass_val = self.shared_data['pass_val'][
                    int(self.domuid) - int(monitoring_domU[0])]
                other_pass_val = self.shared_data['pass_val'][
                    int(self.other_domuid) - int(monitoring_domU[0])]
                last_time = self.shared_data['last_time_val']
                now_time = time.time()
                if last_time == 0:
                    last_time = now_time
                    self.shared_data['last_time_val'] = now_time
                # print('domuid',self.domuid,'last_time', last_time,'now_time',now_time)

                self.shared_data[
                    "contention_time_passed"] += now_time - last_time
                self.shared_data['last_time_val'] = now_time
                # print(self.shared_data["contention_time_passed"])

                if my_pass_val <= other_pass_val:
                    other_cur_bw = self.timeslice_us - cur_bw
                else:
                    cur_bw = self.timeslice_us - other_cur_bw
                    self.pid.reset()

                process_unit_time = 2.5
                if self.shared_data[
                        "contention_time_passed"] >= process_unit_time:  # and int(self.shared_data["contention_time_passed"])%5==0:
                    self.shared_data["contention_time_passed"] = 0
                    if my_pass_val <= other_pass_val:
                        self.shared_data['pass_val'][
                            int(self.domuid) -
                            int(monitoring_domU[0])] += self.shared_data[
                                'stride_val'][int(self.domuid) -
                                              int(monitoring_domU[0])]
                    else:
                        self.shared_data['pass_val'][
                            int(self.other_domuid) -
                            int(monitoring_domU[0])] += self.shared_data[
                                'stride_val'][int(self.other_domuid) -
                                              int(monitoring_domU[0])]

                    with open("info.txt", "a") as myfile:
                        myfile.write(self.domuid + " " + self.domuid +
                                     " time slice len 6" + " " +
                                     str(now_time) + "\n")

                # print('domuid',self.domuid,'other_cur_bw', other_cur_bw,'cur_bw',cur_bw)

            else:
                # print('domuid',self.domuid,'other_cur_bw', other_cur_bw,'cur_bw',cur_bw)

                self.shared_data['last_time_val'] = time.time()

        other_info = self.shared_data[self.other_domuid]
        myinfo = self.shared_data[self.domuid]
        if self.rtxen_or_credit == 1:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = cur_bw
            xen_interface.sched_rtds(self.domuid, self.timeslice_us, cur_bw,
                                     [])
            xen_interface.sched_rtds(self.other_domuid, self.timeslice_us,
                                     other_cur_bw, [])

        elif self.rtxen_or_credit == 0:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = cur_bw
            xen_interface.sched_credit(self.domuid, cur_bw)
            xen_interface.sched_credit(self.other_domuid, other_cur_bw)

        buf = 10000
        self.shared_data['cnt'] = (self.shared_data['cnt'] + 1) % buf
        time_now = str(time.time())
        info = self.domuid + " " + str(heart_rate) + " hr " + time_now + "\n"
        info += self.domuid + " " + str(
            cur_bw /
            self.timeslice_us) + " cpu1 cpu2 cpu3 cpu4 cpu5 " + time_now + "\n"
        info += self.other_domuid + " " + str(
            other_cur_bw /
            self.timeslice_us) + " other cpu2 cpu3 cpu4 cpu5 " + time_now

        # if self.shared_data['cnt']%buf!=0:
        # 	with open("info.txt", "a") as myfile:
        # 		myfile.write(info+"\n")
        # else:
        # 	with open("info.txt", "w") as myfile:
        #		myfile.write(info+"\n")
        with open("info.txt", "a") as myfile:
            myfile.write(info + "\n")

        return
Esempio n. 9
0
    def res_allocat(self, heart_rate):

        minn = int(self.timeslice_us * 0.01)
        print(self.domuid, heart_rate, self.algo)

        # if int(self.domuid)>=3:
        # 	#print("dummy",int(self.domuid)-2,"heartrate:",heart_rate)
        # 	buf=50
        # 	self.shared_data['cnt'] = (self.shared_data['cnt']+1)%buf
        # 	info = self.domuid+" "+str(heart_rate)+" dummy is here"
        # 	if self.shared_data['cnt']%buf!=0:
        # 		with open("info.txt", "a") as myfile:
        # 			myfile.write(info+"\n")
        # 	else:
        # 		with open("info.txt", "w") as myfile:
        # 			myfile.write(info+"\n")

        # 	return

        # tab='               dom '+str(int(self.domuid))
        # if int(self.domuid)<2:
        # 	tab='dom '+str(int(self.domuid))
        # print(tab,'heart_rate',heart_rate)

        cur_bw = 0
        myinfo = self.shared_data[self.domuid]

        if self.xen_sched == 1:
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['b'])
        elif self.xen_sched == 0:
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    cur_bw = int(vcpu['w'])

        if self.algo == 3:
            # apid algo
            output = self.pid.update(heart_rate)
            # output+=self.timeslice_us/2
            if self.pid.start > 0:
                tmp_cur_bw = output + cur_bw  #int(output*cur_bw+cur_bw)-int(output*cur_bw+cur_bw)%100
                if tmp_cur_bw >= self.timeslice_us - minn:  #dummy
                    cur_bw = self.timeslice_us - minn
                elif tmp_cur_bw <= minn:  #self.timeslice_us/3:
                    cur_bw = minn  #int(self.timeslice_us/3)
                else:
                    cur_bw = tmp_cur_bw

            cur_bw = int(cur_bw)  #-int(cur_bw)%100

        else:
            self.pid.reset()

        if self.algo == 4:
            # aimd algo
            alpha = 3.5
            beta = .9
            free = self.timeslice_us - cur_bw

            # if(heart_rate<self.mid):
            # 	if cur_bw<self.timeslice_us-minn:
            # 		free=free*beta
            # 		cur_bw=self.timeslice_us-free
            # 	else:
            # 		cur_bw=self.timeslice_us-minn
            # if(heart_rate>self.mid):
            # 	if cur_bw>minn:
            # 		free+=alpha*minn
            # 		cur_bw=self.timeslice_us-free

            if (heart_rate < self.min_heart_rate):
                if cur_bw < self.timeslice_us - minn:
                    free = free * beta
                    cur_bw = self.timeslice_us - free
                else:
                    cur_bw = self.timeslice_us - minn
            if (heart_rate > self.max_heart_rate):
                if cur_bw > minn:
                    free += alpha * minn
                    cur_bw = self.timeslice_us - free
            cur_bw = int(cur_bw)  #-int(cur_bw)%100
            print("      ", cur_bw)

        if self.algo == 1:

            alpha = 1
            beta = .9
            free = self.timeslice_us - cur_bw

            if (heart_rate < self.mid):
                if cur_bw < self.timeslice_us - minn:
                    free = free * beta
                    cur_bw = self.timeslice_us - free
                else:
                    cur_bw = self.timeslice_us - minn
            if (heart_rate > self.mid):
                if cur_bw > minn:
                    free += alpha * minn
                    cur_bw = self.timeslice_us - free

            # if(heart_rate<self.mid):
            # 	if cur_bw<self.timeslice_us-2*minn: #dummy
            # 		cur_bw+=minn
            # if(heart_rate>self.mid):
            # 	if cur_bw>minn:
            # 		cur_bw-=minn

            # if(heart_rate<self.min_heart_rate):
            # 	if cur_bw<self.timeslice_us-2*minn: #dummy
            # 		cur_bw+=minn
            # if(heart_rate>self.max_heart_rate):
            # 	if cur_bw>minn:
            # 		cur_bw-=minn
            cur_bw = int(cur_bw)  #-int(cur_bw)%100

        if self.algo == 2:
            default_bw = int(self.timeslice_us - minn)  #dummy
            if cur_bw != default_bw:
                cur_bw = default_bw
            cur_bw = int(cur_bw)  #-int(cur_bw)%100

        if self.algo == 0:
            default_bw = int(self.timeslice_us / 2)  #dummy
            if cur_bw != default_bw:
                cur_bw = default_bw
            cur_bw = 2000 / 2

        other_cur_bw = 0
        other_info = self.shared_data[self.other_domuid]
        cur_bw = cur_bw
        myinfo = self.shared_data[self.domuid]

        if self.xen_sched == 1:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    other_cur_bw = vcpu['b']

        elif self.xen_sched == 0:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    other_cur_bw = vcpu['w']
        # print('domuid',self.domuid,'other_cur_bw', other_cur_bw,'cur_bw',cur_bw)

        if cur_bw + other_cur_bw > self.timeslice_us:

            my_pass_val = self.shared_data['pass_val'][int(self.domuid) -
                                                       int(monitoring_domU[0])]
            other_pass_val = self.shared_data['pass_val'][
                int(self.other_domuid) - int(monitoring_domU[0])]
            last_time = self.shared_data['last_time_val']
            now_time = time.time()
            if last_time == 0:
                last_time = now_time
                self.shared_data['last_time_val'] = now_time
            # print('domuid',self.domuid,'last_time', last_time,'now_time',now_time)

            self.shared_data["contention_time_passed"] += now_time - last_time
            self.shared_data['last_time_val'] = now_time
            # print(self.shared_data["contention_time_passed"])

            if my_pass_val <= other_pass_val:
                other_cur_bw = self.timeslice_us - cur_bw
            else:
                cur_bw = self.timeslice_us - other_cur_bw
                self.pid.reset()

            process_unit_time = 2.5
            if self.shared_data[
                    "contention_time_passed"] >= process_unit_time:  # and int(self.shared_data["contention_time_passed"])%5==0:
                self.shared_data["contention_time_passed"] = 0
                if my_pass_val <= other_pass_val:
                    self.shared_data['pass_val'][int(self.domuid) - int(
                        monitoring_domU[0])] += self.shared_data['stride_val'][
                            int(self.domuid) - int(monitoring_domU[0])]
                else:
                    self.shared_data['pass_val'][int(self.other_domuid) - int(
                        monitoring_domU[0])] += self.shared_data['stride_val'][
                            int(self.other_domuid) - int(monitoring_domU[0])]

                with open("info.txt", "a") as myfile:
                    myfile.write(self.domuid + " " + self.domuid +
                                 " time slice len 6" + " " + str(now_time) +
                                 "\n")

            # print('domuid',self.domuid,'other_cur_bw', other_cur_bw,'cur_bw',cur_bw)

        else:
            # print('domuid',self.domuid,'other_cur_bw', other_cur_bw,'cur_bw',cur_bw)

            self.shared_data['last_time_val'] = time.time()

        if self.xen_sched == 1:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['b'] = cur_bw
            xen_interface.sched_rtds(self.domuid, self.timeslice_us, cur_bw,
                                     [])
            xen_interface.sched_rtds(self.other_domuid, self.timeslice_us,
                                     other_cur_bw, [])

        elif self.xen_sched == 0:
            for vcpu in other_info:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = other_cur_bw
            for vcpu in myinfo:
                if vcpu['pcpu'] != -1:
                    vcpu['w'] = cur_bw
            xen_interface.sched_credit(self.domuid, cur_bw)
            xen_interface.sched_credit(self.other_domuid, other_cur_bw)

        buf = 10000
        self.shared_data['cnt'] = (self.shared_data['cnt'] + 1) % buf
        time_now = str(time.time())
        info = self.domuid + " " + str(heart_rate) + " hr " + time_now + "\n"
        info += self.domuid + " " + str(
            cur_bw /
            self.timeslice_us) + " cpu1 cpu2 cpu3 cpu4 cpu5 " + time_now + "\n"
        info += self.other_domuid + " " + str(
            other_cur_bw /
            self.timeslice_us) + " other cpu2 cpu3 cpu4 cpu5 " + time_now

        # if self.shared_data['cnt']%buf!=0:
        # 	with open("info.txt", "a") as myfile:
        # 		myfile.write(info+"\n")
        # else:
        # 	with open("info.txt", "w") as myfile:
        #		myfile.write(info+"\n")
        with open("info.txt", "a") as myfile:
            myfile.write(info + "\n")

        return
Esempio n. 10
0
        #		myfile.write(info+"\n")
        with open("info.txt", "a") as myfile:
            myfile.write(info + "\n")

        return

    # https://xenbits.xen.org/docs/unstable/man/xl.1.html#SCHEDULER-SUBCOMMANDS
    # cpupool, vcpupin, rtds-budget,period, extratime, vcpu-list


threadLock = threading.Lock()
threads = []
shared_data = xen_interface.get_global_info()

for uid in monitoring_domU:
    xen_interface.sched_rtds(int(uid), timeslice_us, 2000 / 2, [])

# if '1' in shared_data['rtxen']:
# 	xen_interface.sched_rtds(1,timeslice_us,default_bw,[])
# 	xen_interface.sched_rtds(2,timeslice_us,timeslice_us-default_bw,[])
# if '1' in shared_data['xen']:
# 	xen_interface.sched_credit(1,default_bw)
# 	xen_interface.sched_credit(2,timeslice_us-default_bw)

# for i,domuid in enumerate(shared_data['rtxen']):
# 	xen_interface.sched_rtds(domuid,timeslice_us,default_bw,[])
# 	xen_interface.sched_rtds(str(int(domuid)+2),timeslice_us,timeslice_us-default_bw,[])

# for domuid in shared_data['xen']:
# 	xen_interface.sched_credit(domuid,default_bw)
# 	xen_interface.sched_credit(str(int(domuid)+2),timeslice_us-default_bw)
Esempio n. 11
0
        #		myfile.write(info+"\n")
        with open("info.txt", "a") as myfile:
            myfile.write(info + "\n")

        return

    # https://xenbits.xen.org/docs/unstable/man/xl.1.html#SCHEDULER-SUBCOMMANDS
    # cpupool, vcpupin, rtds-budget,period, extratime, vcpu-list


threadLock = threading.Lock()
threads = []
shared_data = xen_interface.get_global_info()

for uid in monitoring_domU:
    xen_interface.sched_rtds(int(uid), timeslice_us, args["static_alloc"], [])

# if '1' in shared_data['rtxen']:
# 	xen_interface.sched_rtds(1,timeslice_us,default_bw,[])
# 	xen_interface.sched_rtds(2,timeslice_us,timeslice_us-default_bw,[])
# if '1' in shared_data['xen']:
# 	xen_interface.sched_credit(1,default_bw)
# 	xen_interface.sched_credit(2,timeslice_us-default_bw)

# for i,domuid in enumerate(shared_data['rtxen']):
# 	xen_interface.sched_rtds(domuid,timeslice_us,default_bw,[])
# 	xen_interface.sched_rtds(str(int(domuid)+2),timeslice_us,timeslice_us-default_bw,[])

# for domuid in shared_data['xen']:
# 	xen_interface.sched_credit(domuid,default_bw)
# 	xen_interface.sched_credit(str(int(domuid)+2),timeslice_us-default_bw)