<commit_before>#include <unistd.h>
#include <rte_lcore.h>
#include <stats.h>
#include <eth.h>
#include <rx.h>
#include <tx.h>
#include <queued_pkts.h>
#include <tw_api.h>


int Printing_Enable = 1;
int tw_loop_init(tw_loop_t * event_loop) { //TODO secs_to_run for  event loop
    event_loop->data = NULL;
//    int core_id = rte_lcore_id();
    if (global_pps_limit)
        global_pps_delay = 10000000000 / global_pps_limit;
    else
        global_pps_delay = 0;
    return 0;
}

int tw_stop(tw_loop_t * event_loop) {
    event_loop->stop_flag = 0;
    return 0;
}

tw_loop_t * tw_default_loop(uint16_t time_to_run) {
    tw_loop_t * loop = rte_malloc("tw_loop_t *", sizeof (tw_loop_t), RTE_CACHE_LINE_SIZE);
    loop->secs_to_run = time_to_run;
    return loop;
}

tw_rx_t * tw_rx_init(tw_loop_t * loop) {
    tw_rx_t * temp_rx_handle = loop->rx_handle_queue;
    //udp_handle = loop->rx_handle_queue;

    if (temp_rx_handle == NULL) {
        temp_rx_handle = rte_malloc("tw_udp_t *", sizeof (tw_udp_t), RTE_CACHE_LINE_SIZE);
        loop->rx_handle_queue = temp_rx_handle;
    } else {
        while (temp_rx_handle->next != NULL)
            temp_rx_handle = temp_rx_handle->next;
        temp_rx_handle->next = rte_malloc("tw_udp_t *", sizeof (tw_udp_t), RTE_CACHE_LINE_SIZE);
        temp_rx_handle = temp_rx_handle->next;
    }

    //TODO populate tw_loop_t entries if needed
    //udp_handle = temp_udp_handle;
    temp_rx_handle->handle_type = TW_UDP_HANDLE;
    //loop->active_handles++;
    //udp_handle = temp_udp_handle;
    //udp_handle->flags = 0;
    //return 0;
    return temp_rx_handle;
}

int tw_rx_start(tw_rx_t * rx_handle, void * recv_cb) {
    if (rx_handle == NULL)
        return -1;
    rx_handle->recv_cb = recv_cb;
    return 0;
}

tw_tx_t * tw_tx_init(tw_loop_t * loop) {
    tw_tx_t * temp_handle = loop->tx_handle_queue;
    if (temp_handle == NULL) {
        temp_handle = rte_malloc("tw_tx_t *", sizeof (tw_tx_t), RTE_CACHE_LINE_SIZE);
        loop->tx_handle_queue = temp_handle;
    } else {
        while (temp_handle->next != NULL)
            temp_handle = temp_handle->next;
        temp_handle->next = rte_malloc("tw_tx_t *", sizeof (tw_tx_t), RTE_CACHE_LINE_SIZE);
        temp_handle = temp_handle->next;
    }
	
    //tx_handle = (tw_tx_t *) temp_handle;
    temp_handle->handle_type = TW_TX_HANDLE;
    loop->active_handles++;
    return temp_handle;
}

int tw_tx_start(tw_tx_t * tx_handle, void * tx_cb) {
    if (tx_handle == NULL)
        return -1;

    tx_handle->tx_cb = tx_cb;
    return 0;
}

tw_timer_t * tw_timer_init(tw_loop_t * loop) {
    tw_timer_t * temp_handle = loop->timer_handle_queue;
    if (temp_handle == NULL) {
        temp_handle = rte_malloc("tw_timer_t *", sizeof (tw_timer_t), RTE_CACHE_LINE_SIZE);
        loop->timer_handle_queue = temp_handle;
    } else {
        while (temp_handle->next != NULL)
            temp_handle = temp_handle->next;
        temp_handle->next = rte_malloc("tw_timer_t *", sizeof (tw_timer_t), RTE_CACHE_LINE_SIZE);
        temp_handle = temp_handle->next;
    }

    //TODO populate tw_loop_t entries if needed
    //timer_handle = (tw_timer_t *) temp_handle;
    temp_handle->handle_type = TW_TIMER_HANDLE;
    loop->active_handles++;
    return temp_handle;
}

/*int tw_timer_bind(tw_timer_t * timer_handle, struct tw_sockaddr_in * addr, int sock_fd, uint8_t flags) {
    timer_handle->flags = flags;
    timer_handle->sock_fd = sock_fd;
    timer_handle->dst_addr = addr;
    return 0;
}*/

int tw_timer_start(tw_timer_t* timer_handle, tw_timer_cb timer_cb, uint64_t timeout) {
    if (timer_handle == NULL)
        return -1;
    timer_handle->timer_cb = timer_cb;
    timer_handle->timeout = (timeout) *( rte_get_tsc_hz() / 1000 );
    return 0;
}

int tw_run(tw_loop_t * event_loop) {

	uint64_t stats_calc_lim = stats_calc_limit* rte_get_tsc_hz();
    uint8_t/* infinite_loop = 0,*/ continue_loop = 1;
    //if (event_loop->secs_to_run == INFINITE_LOOP)
      //  infinite_loop = 1;
    int num_rx_pkts = 0, pkt_count = 0, i;
    uint64_t curr_time_cycle = 0, /*prev_queued_pkts_cycle = 0,*/ prev_stats_calc = 0, time_diff = 0;
    //uint64_t loop_start_time = tw_get_current_timer_cycles();
    struct lcore_conf *qconf = &lcore_conf[rte_lcore_id()];
    struct mbuf_table m[qconf->num_port];
    struct rte_mbuf * pkt;
    tw_buf_t temp_buffer;
    struct ether_hdr * temp_eth;

    tw_rx_t * temp_rx_handle;
    tw_tx_t * temp_tx_handle;
    tw_timer_t * temp_timer_handle;

    void (*tw_rx_cb) (tw_rx_t *, tw_buf_t *);
    void (*tw_tx_cb) (tw_tx_t *);
    void (*tw_timer_cb) (tw_timer_t *);

    do {
       /* if (event_loop->stop_flag)
            return 0;*/
        curr_time_cycle = tw_get_current_timer_cycles();
		
        tw_timely_burst();
	time_diff = (curr_time_cycle - prev_stats_calc);
        if (unlikely(time_diff > stats_calc_lim)) {
            tw_calc_global_stats();
            if(Printing_Enable)<commit_msg>Fix the Unused variable warning while compilation of Twister<commit_after>#include <unistd.h>
#include <rte_lcore.h>
#include <stats.h>
#include <eth.h>
#include <rx.h>
#include <tx.h>
#include <queued_pkts.h>
#include <tw_api.h>


int Printing_Enable = 1;
int tw_loop_init(tw_loop_t * event_loop) { //TODO secs_to_run for  event loop
    event_loop->data = NULL;
//    int core_id = rte_lcore_id();
    if (global_pps_limit)
        global_pps_delay = 10000000000 / global_pps_limit;
    else
        global_pps_delay = 0;
    return 0;
}

int tw_stop(tw_loop_t * event_loop) {
    event_loop->stop_flag = 0;
    return 0;
}

tw_loop_t * tw_default_loop(uint16_t time_to_run) {
    tw_loop_t * loop = rte_malloc("tw_loop_t *", sizeof (tw_loop_t), RTE_CACHE_LINE_SIZE);
    loop->secs_to_run = time_to_run;
    return loop;
}

tw_rx_t * tw_rx_init(tw_loop_t * loop) {
    tw_rx_t * temp_rx_handle = loop->rx_handle_queue;
    //udp_handle = loop->rx_handle_queue;

    if (temp_rx_handle == NULL) {
        temp_rx_handle = rte_malloc("tw_udp_t *", sizeof (tw_udp_t), RTE_CACHE_LINE_SIZE);
        loop->rx_handle_queue = temp_rx_handle;
    } else {
        while (temp_rx_handle->next != NULL)
            temp_rx_handle = temp_rx_handle->next;
        temp_rx_handle->next = rte_malloc("tw_udp_t *", sizeof (tw_udp_t), RTE_CACHE_LINE_SIZE);
        temp_rx_handle = temp_rx_handle->next;
    }

    //TODO populate tw_loop_t entries if needed
    //udp_handle = temp_udp_handle;
    temp_rx_handle->handle_type = TW_UDP_HANDLE;
    //loop->active_handles++;
    //udp_handle = temp_udp_handle;
    //udp_handle->flags = 0;
    //return 0;
    return temp_rx_handle;
}

int tw_rx_start(tw_rx_t * rx_handle, void * recv_cb) {
    if (rx_handle == NULL)
        return -1;
    rx_handle->recv_cb = recv_cb;
    return 0;
}

tw_tx_t * tw_tx_init(tw_loop_t * loop) {
    tw_tx_t * temp_handle = loop->tx_handle_queue;
    if (temp_handle == NULL) {
        temp_handle = rte_malloc("tw_tx_t *", sizeof (tw_tx_t), RTE_CACHE_LINE_SIZE);
        loop->tx_handle_queue = temp_handle;
    } else {
        while (temp_handle->next != NULL)
            temp_handle = temp_handle->next;
        temp_handle->next = rte_malloc("tw_tx_t *", sizeof (tw_tx_t), RTE_CACHE_LINE_SIZE);
        temp_handle = temp_handle->next;
    }
	
    //tx_handle = (tw_tx_t *) temp_handle;
    temp_handle->handle_type = TW_TX_HANDLE;
    loop->active_handles++;
    return temp_handle;
}

int tw_tx_start(tw_tx_t * tx_handle, void * tx_cb) {
    if (tx_handle == NULL)
        return -1;

    tx_handle->tx_cb = tx_cb;
    return 0;
}

tw_timer_t * tw_timer_init(tw_loop_t * loop) {
    tw_timer_t * temp_handle = loop->timer_handle_queue;
    if (temp_handle == NULL) {
        temp_handle = rte_malloc("tw_timer_t *", sizeof (tw_timer_t), RTE_CACHE_LINE_SIZE);
        loop->timer_handle_queue = temp_handle;
    } else {
        while (temp_handle->next != NULL)
            temp_handle = temp_handle->next;
        temp_handle->next = rte_malloc("tw_timer_t *", sizeof (tw_timer_t), RTE_CACHE_LINE_SIZE);
        temp_handle = temp_handle->next;
    }

    //TODO populate tw_loop_t entries if needed
    //timer_handle = (tw_timer_t *) temp_handle;
    temp_handle->handle_type = TW_TIMER_HANDLE;
    loop->active_handles++;
    return temp_handle;
}

/*int tw_timer_bind(tw_timer_t * timer_handle, struct tw_sockaddr_in * addr, int sock_fd, uint8_t flags) {
    timer_handle->flags = flags;
    timer_handle->sock_fd = sock_fd;
    timer_handle->dst_addr = addr;
    return 0;
}*/

int tw_timer_start(tw_timer_t* timer_handle, tw_timer_cb timer_cb, uint64_t timeout) {
    if (timer_handle == NULL)
        return -1;
    timer_handle->timer_cb = timer_cb;
    timer_handle->timeout = (timeout) *( rte_get_tsc_hz() / 1000 );
    return 0;
}

int tw_run(tw_loop_t * event_loop) {

	uint64_t stats_calc_lim = stats_calc_limit* rte_get_tsc_hz();
    uint8_t/* infinite_loop = 0,*/ continue_loop = 1;
    //if (event_loop->secs_to_run == INFINITE_LOOP)
      //  infinite_loop = 1;
    int num_rx_pkts = 0, pkt_count = 0, i;
    uint64_t curr_time_cycle = 0, /*prev_queued_pkts_cycle = 0,*/ prev_stats_calc = 0, time_diff = 0;
    //uint64_t loop_start_time = tw_get_current_timer_cycles();
    struct lcore_conf *qconf = &lcore_conf[rte_lcore_id()];
    struct mbuf_table m[qconf->num_port];
    struct rte_mbuf * pkt;
    tw_buf_t temp_buffer;

    tw_rx_t * temp_rx_handle;
    tw_tx_t * temp_tx_handle;
    tw_timer_t * temp_timer_handle;

    void (*tw_rx_cb) (tw_rx_t *, tw_buf_t *);
    void (*tw_tx_cb) (tw_tx_t *);
    void (*tw_timer_cb) (tw_timer_t *);

    do {
       /* if (event_loop->stop_flag)
            return 0;*/
        curr_time_cycle = tw_get_current_timer_cycles();
		
        tw_timely_burst();
	time_diff = (curr_time_cycle - prev_stats_calc);
        if (unlikely(time_diff > stats_calc_lim)) {
            tw_calc_global_stats();
            if(Printing_Enable)
{'fraction_non_alphanumeric': 0.11554748941318814, 'fraction_numerical': 0.0102843315184513, 'mean_word_length': 3.2772746873652436, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '211651', 'n_tokens_mistral': 3963, 'n_tokens_neox': 3834, 'n_words': 684}