Professional Documents
Culture Documents
REPORTUNIXDAA
REPORTUNIXDAA
ENGINEERING
DAA-UNIX EL COMPONENT
Assistant professors
Dept. of ISE
RV College of Engineering
GROUP MEMBERS:
Name USN
ACKNOWLEDGEMENT
The completion of this report could not have been possible without the assistance and
guidance of our professors, BK Srinivas and Swetha S. We cannot express enough
thanks for his continued support and supervision throughout this undertaking.
We would also like to express our deep sense of gratitude towards our HOD, Dr B.M
Sagar, and Principal, Dr K N Subramanya for giving us this opportunity and for their
guidance in the completion of our report. Lastly, we would also like to thank all the
faculty members for their constant encouragement and cooperation.
1 ABSTRACT 4
2 INTRODUCTION 4
3 METHODOLOGY 5
4 IMPLEMENTATION 7
5 OUTPUT 19
6 CONCLUSION 21
If there are a large number of scheduled tasks in a system, and each of the large number
of scheduled tasks uses its own scheduler to manage the life cycle of the task, it is
wasteful of cpu resources and inefficient. The time wheel is a scheduling model that
makes efficient use of thread resources for batch scheduling. It binds a large number of
scheduled tasks to a single scheduler and uses this scheduler to manage, trigger and
runnable all tasks. This allows for efficient management of various delayed tasks,
periodic tasks, notification tasks, etc.
INTRODUCTION:
Timer is a relatively early implementation that allows for fixed-period tasks, as well as
deferred tasks; Timer starts an asynchronous thread to execute a task when it is due, and
the task can be scheduled only once, or repeated several times periodically.
Timers have very many scenarios, which you should encounter frequently in your
normal work, such as generating monthly statistical reports, financial reconciliation,
membership points settlement, email push, etc., are all scenarios of timer usage.
Timers generally have three forms of performance: execution at a fixed period,
execution after a certain delay, and execution at a specified time.
The essence of a timer is to design a data structure that can store and schedule a
collection of tasks, and the closer the deadline, the higher the priority of the task. So
how does a timer know if a task is due or not? A timer needs to be polled to check if
a task is due every other time slice.
If there are a large number of scheduled tasks in a system, and each of the large number
of scheduled tasks uses its own scheduler to manage the life cycle of the task, it is
wasteful of CPU resources and inefficient. The time wheel is a scheduling model that
makes efficient use of thread resources for batch scheduling. It binds a large number of
scheduled tasks to a single scheduler and uses this scheduler to manage, trigger and
runnable all tasks. This allows for efficient management of various delayed tasks,
periodic tasks, notification tasks, etc.
So the internal structure of a timer typically requires a task queue and an asynchronous
polling thread, and can provide three basic operations.
Schedule adds a task to the task collection.
Cancel cancels a task.
Run executes a task that is due.
ll_t* init_singly_ll(){
return calloc(1, sizeof(ll_t));
}
int
singly_ll_add_node(ll_t* ll, singly_ll_node_t *node){
if(!ll) return -1;
if(!node) return -1;
if(!GET_HEAD_SINGLY_LL(ll)){
GET_HEAD_SINGLY_LL(ll) = node;
INC_NODE_COUNT_SINGLY_LL(ll);
return 0;
}
node->next = GET_HEAD_SINGLY_LL(ll);
GET_HEAD_SINGLY_LL(ll) = node;
INC_NODE_COUNT_SINGLY_LL(ll);
return 0;
}
int
singly_ll_add_node_by_val(ll_t *ll, void* data){
int
singly_ll_delete_node(ll_t *ll, singly_ll_node_t *node){
if(!ll) return -1;
if(!GET_HEAD_SINGLY_LL(ll) || !node) return 0;
singly_ll_node_t *trav = NULL;
/*if node is not the last node*/
if(node->next){
singly_ll_node_t *temp = NULL;
node->data = node->next->data;
temp = node->next;
node->next = node->next->next;
free(temp);
DEC_NODE_COUNT_SINGLY_LL(ll);
return 0;
}
trav->next = NULL;
free(node);
DEC_NODE_COUNT_SINGLY_LL(ll);
return 0;
}
if(head == node){
GET_HEAD_SINGLY_LL(ll) = GET_NEXT_NODE_SINGLY_LL(head);
DEC_NODE_COUNT_SINGLY_LL(ll);
node->next = NULL;
return 0;
}
prev = head;
head = GET_NEXT_NODE_SINGLY_LL(head);
for(i =1; i < GET_NODE_COUNT_SINGLY_LL(ll); i++){
if(head != node){
prev = head;
head = GET_NEXT_NODE_SINGLY_LL(head);
continue;
}
prev->next = GET_NEXT_NODE_SINGLY_LL(head);
GET_NEXT_NODE_SINGLY_LL(head) = NULL;
DEC_NODE_COUNT_SINGLY_LL(ll);
node->next = NULL;
return 0;
}
printf("%s(%d) : Error : node not found\n", __FUNCTION__, __LINE__);
return -1;
}
unsigned int
unsigned int
singly_ll_remove_node_by_value(ll_t *ll, void *data, int size){
if(!ll || !GET_HEAD_SINGLY_LL(ll)) return 0;
unsigned int curren_node_count = GET_NODE_COUNT_SINGLY_LL(ll);
singly_ll_node_t* trav = GET_HEAD_SINGLY_LL(ll);
while(trav != NULL){
if(memcmp(trav->data, data, size) == 0){
singly_ll_remove_node(ll, trav);
return curren_node_count - GET_NODE_COUNT_SINGLY_LL(ll);
}
trav = trav->next;
}
return curren_node_count - GET_NODE_COUNT_SINGLY_LL(ll);
}
singly_ll_node_t*
singly_ll_get_node_by_data_ptr(ll_t *ll, void *data){
if(!ll || !GET_HEAD_SINGLY_LL(ll)) return NULL;
int i = 0;
singly_ll_node_t *head = GET_HEAD_SINGLY_LL(ll);
bool_t
is_singly_ll_empty(ll_t *ll){
if(!ll) assert(0);
if(ll->node_count == 0)
return LL_TRUE;
return LL_FALSE;
}
void
reverse_singly_ll(ll_t *ll){
if(!ll) assert(0) ;
if(is_singly_ll_empty(ll)) return;
if(GET_NODE_COUNT_SINGLY_LL(ll) == 1) return;
singly_ll_node_t *p1 = GET_HEAD_SINGLY_LL(ll),
*p2 = ll->head->next, *p3 = NULL;
void
delete_singly_ll(ll_t *ll){
if(!ll) return;
if(is_singly_ll_empty(ll)){
return;
}
do{
free(head);
head = next;
if(next)
next = GET_NEXT_NODE_SINGLY_LL(next);
} while(head);
ll->node_count = 0;
ll->head = NULL;
}
#if 0
int
main(int argc, char **argv){
#if 1
int n = 5;
unsigned int num_nodes_removed = singly_ll_remove_node_by_value(list, &n, sizeof(int));
printf("number of noded removed = %d\n", num_nodes_removed);
print_singly_LL(list);
#endif
n = 1;
singly_ll_remove_node_by_value(list, &n, sizeof(int));
//reverse_singly_ll(list);
print_singly_LL(list);
return 0;
}
#endif
//main.c
#include <stdio.h>
#include <memory.h>
#include "WheelTimer.h"
//main.c
#define WHEEL_SIZE 60
#define WHEEL_TIMER_CLOCK_TIC_INTERVAL 1 // sec
wheel_timer_t *wt;
void
generate_general_query(int vlan){
static int count = 0;
printf("%s() : Query no : %d : general query is generated for vlan %d\n", __FUNCTION__, count++, vlan);
}
void
generate_pim_hello(int vlan){
static int count = 0;
printf("%s() : Query no : %d : pim_hello is generated for vlan %d\n", __FUNCTION__, count++, vlan);
}
void
wrapper_generate_pim_hello(void *arg, int arg_size){
int vlan = *(int *)arg;
generate_pim_hello(vlan);
}
void
void
main_menu(wheel_timer_t *wt){
wheel_timer_elem_t *gq_wt_elem = NULL,
*pim_hello_wt_elem = NULL,
*ospf_hello_wt_elem = NULL;
do{
printf("\nMain Menu\n");
printf("*************\n");
printf("1. dump Wheel Timer\n");
printf("2. Register General Query Event\n");
printf("3. Register Pim Hello Event\n");
printf("4. Register Ospf Hello Event\n");
printf("5. Reset Wheel Timer\n");
printf("6. de-Register General Query Event\n");
printf("7. de-Register Pim Hello Event\n");
printf("8. de-Register Ospf Hello Event\n");
printf("9. Exit\n");
printf("10. Reschedule general query\n");
printf("11. Reschedule pim hello\n");
printf("12. Reschedule ospf hello\n");
int choice;
scanf("%d", &choice);
switch(choice){
case 10:
{
int new_time_interval = 0;
printf("Enter new time interval : ");
break;
case 6:
de_register_app_event(wt, gq_wt_elem);
gq_wt_elem = NULL;
break;
case 7:
de_register_app_event(wt, pim_hello_wt_elem);
break;
case 8:
de_register_app_event(wt, ospf_hello_wt_elem);
break;
case 1:
print_wheel_timer(wt);
break;
case 2:
{
int vlan_no;
printf("Enter vlan no : ");
scanf("%d", &vlan_no);
char is_recursive;
printf("Is Recirsive (1/0) ? ");
}
break;
case 3:
{
int vlan_no;
printf("Enter vlan no : ");
scanf("%d", &vlan_no);
char is_recursive;
printf("Is Recirsive (1/0) ? ");
scanf("%d", (int *)&is_recursive);
int time_interval;
printf("time_interval ? ");
scanf("%d", &time_interval);
pim_hello_wt_elem = register_app_event(wt, wrapper_generate_pim_hello,
(void *)&vlan_no, sizeof(vlan_no), time_interval, is_recursive);
}
break;
case 4:
{
int vlan_no;
printf("Enter vlan no : ");
scanf("%d", &vlan_no);
char is_recursive;
printf("Is Recirsive (1/0) ? ");
case 5:
reset_wheel_timer(wt);
break;
case 9:
exit(0);
default:
break;
}
}
while(1);
}
int
main(int argc, char **argv){
wt = init_wheel_timer(WHEEL_SIZE, WHEEL_TIMER_CLOCK_TIC_INTERVAL);
start_wheel_timer(wt);
main_menu(wt);
return 0;
}
OUTPUT: