Skip to content

Commit

Permalink
undo changes to tb
Browse files Browse the repository at this point in the history
  • Loading branch information
Catherine Meadows committed Jul 27, 2020
1 parent 80d9b62 commit 21197ac
Showing 1 changed file with 12 additions and 45 deletions.
57 changes: 12 additions & 45 deletions examples/simple_fwd_tb/forward_tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include <rte_cycles.h>
#include <rte_ip.h>
#include <rte_mbuf.h>
#include <rte_malloc.h>

#include "onvm_nflib.h"
#include "onvm_pkt_helper.h"
Expand All @@ -68,14 +67,12 @@ static uint32_t print_delay = 1000000;
static uint32_t destination;

/* Token Bucket */
struct tb_config {
uint64_t tb_rate; // rate at which tokens are generated (in MBps)
uint64_t tb_depth; // depth of the token bucket (in bytes)
uint64_t tb_tokens; // number of the tokens in the bucket at any given time (in bytes)
static uint64_t tb_rate = 1000; // rate at which tokens are generated (in Mbps)
static uint64_t tb_depth = 10000; // depth of the token bucket (in bytes)
static uint64_t tb_tokens = 10000; // number of the tokens in the bucket at any given time (in bytes)

uint64_t last_cycle;
uint64_t cur_cycles;
};
static uint64_t last_cycle;
static uint64_t cur_cycles;

/* For advanced rings scaling */
rte_atomic16_t signal_exit_flag;
Expand Down Expand Up @@ -103,17 +100,8 @@ usage(const char *progname) {
* Parse the application arguments.
*/
static int
parse_app_args(int argc, char *argv[], const char *progname, struct onvm_nf *nf) {
parse_app_args(int argc, char *argv[], const char *progname) {
int c, dst_flag = 0;
struct tb_config *tb_params;

tb_params = (struct tb_config *)rte_malloc(NULL, sizeof(struct tb_config), 0);
/* Assigning default values */
tb_params->tb_rate = 1000;
tb_params->tb_depth = 10000;
tb_params->tb_tokens = 10000;
tb_params->last_cycle = rte_get_tsc_cycles();
nf->data = (void *)tb_params;

while ((c = getopt(argc, argv, "d:p:D:R:")) != -1) {
switch (c) {
Expand All @@ -125,15 +113,15 @@ parse_app_args(int argc, char *argv[], const char *progname, struct onvm_nf *nf)
print_delay = strtoul(optarg, NULL, 10);
break;
case 'D':
tb_params->tb_depth = strtoul(optarg, NULL, 10);
tb_params->tb_tokens = tb_params->tb_depth;
if (tb_params->tb_depth < 10000) {
tb_depth = strtoul(optarg, NULL, 10);
tb_tokens = tb_depth;
if (tb_depth < 10000) {
RTE_LOG(INFO, APP,
"WARNING: Small values of depth could lead to packet drops.\n");
}
break;
case 'R':
tb_params->tb_rate = strtoul(optarg, NULL, 10);
tb_rate = strtoul(optarg, NULL, 10);
break;
case '?':
usage(progname);
Expand Down Expand Up @@ -196,23 +184,8 @@ do_stats_display(struct rte_mbuf *pkt) {
static int
packet_handler_tb(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta,
__attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) {
struct onvm_nf *nf;
struct tb_config *tb_params;
static uint32_t counter = 0;
uint64_t tokens_produced;
uint64_t tb_rate;
uint64_t tb_depth;
uint64_t tb_tokens;
uint64_t last_cycle;
uint64_t cur_cycles;

nf = nf_local_ctx->nf;
tb_params = (struct tb_config *)nf->data;
tb_rate = tb_params->tb_rate;
tb_depth = tb_params->tb_depth;
tb_tokens = tb_params->tb_tokens;
last_cycle = tb_params->last_cycle;
cur_cycles = tb_params->cur_cycles;

/* Check if length of packet is greater than depth */
if (unlikely(pkt->pkt_len > tb_depth)) {
Expand Down Expand Up @@ -248,10 +221,6 @@ packet_handler_tb(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta,
counter = 0;
}

tb_params->tb_tokens = tb_tokens;
tb_params->last_cycle = last_cycle;
tb_params->cur_cycles = cur_cycles;

return 0;
}

Expand Down Expand Up @@ -290,7 +259,7 @@ thread_main_loop(struct onvm_nf_local_ctx *nf_local_ctx) {
if (onvm_threading_core_affinitize(nf->thread_info.core) < 0)
rte_exit(EXIT_FAILURE, "Failed to affinitize to core %d\n", nf->thread_info.core);

((struct tb_config *)nf->data)->last_cycle = rte_get_tsc_cycles();
last_cycle = rte_get_tsc_cycles();

while (!rte_atomic16_read(&signal_exit_flag)) {
/* Check for a stop message from the manager */
Expand Down Expand Up @@ -327,7 +296,6 @@ int
main(int argc, char *argv[]) {
struct onvm_nf_local_ctx *nf_local_ctx;
struct onvm_nf_function_table *nf_function_table;
struct onvm_nf *nf;
int arg_offset;

const char *progname = argv[0];
Expand All @@ -354,8 +322,7 @@ main(int argc, char *argv[]) {
argc -= arg_offset;
argv += arg_offset;

nf = nf_local_ctx->nf;
if (parse_app_args(argc, argv, progname, nf) < 0) {
if (parse_app_args(argc, argv, progname) < 0) {
onvm_nflib_stop(nf_local_ctx);
rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n");
}
Expand Down

0 comments on commit 21197ac

Please sign in to comment.