Skip to content

Commit

Permalink
Using clang-format similar to Linux Kernel style
Browse files Browse the repository at this point in the history
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#examples
Only need to do

```
docker run --name clang --rm -it \
-v /etc/passwd:/etc/passwd:ro -u `id -u`:`id -g` \
-v $(pwd):/code \
krsna1729/llvm \
bash -c "shopt -s globstar && clang-format -i /code/**/*.[ch]"
```

Signed-off-by: Saikrishna Edupuganti <saikrishna.edupuganti@intel.com>
  • Loading branch information
krsna1729 committed Feb 18, 2019
1 parent d65e865 commit 2583b62
Show file tree
Hide file tree
Showing 112 changed files with 10,981 additions and 11,944 deletions.
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#https://clang.llvm.org/docs/ClangFormatStyleOptions.html#examples
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false

84 changes: 38 additions & 46 deletions cp/cp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#include <rte_version.h>

#ifndef PERF_TEST
/** Temp. work around for support debug log level into DP, DPDK version 16.11.4 */
/** Temp. work around for support debug log level into DP, DPDK version 16.11.4
*/
#if (RTE_VER_YEAR >= 16) && (RTE_VER_MONTH >= 11)
#undef RTE_LOG_LEVEL
#define RTE_LOG_LEVEL RTE_LOG_DEBUG
Expand All @@ -32,7 +33,8 @@
#undef RTE_LOG_DP_LEVEL
#define RTE_LOG_DP_LEVEL RTE_LOG_DEBUG
#endif
#else /* Work around for skip LOG statements at compile time in DP, DPDK 16.11.4 and 18.02 */
#else /* Work around for skip LOG statements at compile time in DP, \
DPDK 16.11.4 and 18.02 */
#if (RTE_VER_YEAR >= 16) && (RTE_VER_MONTH >= 11)
#undef RTE_LOG_LEVEL
#define RTE_LOG_LEVEL RTE_LOG_WARNING
Expand All @@ -46,20 +48,22 @@

#ifdef SYNC_STATS
#include <time.h>
#define DEFAULT_STATS_PATH "./logs/"
#define STATS_HASH_SIZE (1 << 21)
#define ACK 1
#define RESPONSE 2
#define DEFAULT_STATS_PATH "./logs/"
#define STATS_HASH_SIZE (1 << 21)
#define ACK 1
#define RESPONSE 2

typedef long long int _timer_t;

#define GET_CURRENT_TS(now) \
({ \
struct timespec ts; \
now = clock_gettime(CLOCK_REALTIME,&ts) ? \
-1 : (((_timer_t)ts.tv_sec) * 1000000000) + ((_timer_t)ts.tv_nsec); \
now; \
})
#define GET_CURRENT_TS(now) \
({ \
struct timespec ts; \
now = clock_gettime(CLOCK_REALTIME, &ts) \
? -1 \
: (((_timer_t)ts.tv_sec) * 1000000000) + \
((_timer_t)ts.tv_nsec); \
now; \
})

#endif /* SYNC_STATS */
/**
Expand Down Expand Up @@ -150,31 +154,27 @@ extern uint64_t op_id;
* @return
* 0 - indicates success, failure otherwise
*/
int
ddn_by_session_id(uint64_t session_id);
int ddn_by_session_id(uint64_t session_id);

/**
* @brief initializes data plane by creating and adding default entries to
* various tables including session, pcc, metering, etc
*/
void
initialize_tables_on_dp(void);
void initialize_tables_on_dp(void);

/**
* Central working function of the control plane. Reads message from s11/pcap,
* calls appropriate function to handle message, writes response
* message (if any) to s11/pcap
*/
void
control_plane(void);
void control_plane(void);

#ifdef ZMQ_COMM
/**
* @brief Adds the current op_id to the hash table used to account for NB
* Messages
*/
void
add_resp_op_id_hash(void);
void add_resp_op_id_hash(void);

/**
* @brief Deletes the op_id from the hash table used to account for NB
Expand All @@ -183,10 +183,9 @@ add_resp_op_id_hash(void);
* op_id received in process_resp_msg message to indicate message
* was received and processed by the DPN
*/
void
del_resp_op_id(uint64_t resp_op_id);
void del_resp_op_id(uint64_t resp_op_id);

#endif /* ZMQ_COMM */
#endif /* ZMQ_COMM */

#ifdef CP_BUILD
#ifdef ZMQ_COMM
Expand All @@ -198,10 +197,9 @@ del_resp_op_id(uint64_t resp_op_id);
* @return
* 0 inicates success, error otherwise
*/
int
cb_ddn(uint64_t sess_id);
int cb_ddn(uint64_t sess_id);

#endif /* ZMQ_COMM */
#endif /* ZMQ_COMM */

/**
* @brief To Downlink data notification ack of user.
Expand All @@ -214,14 +212,13 @@ cb_ddn(uint64_t sess_id);
* - 0 on success
* - -1 on failure
*/
int
send_ddn_ack(struct dp_id dp_id,
struct downlink_data_notification ddn_ack);
int send_ddn_ack(struct dp_id dp_id, struct downlink_data_notification ddn_ack);

#endif /* CP_BUILD */
#endif /* CP_BUILD */

#ifdef SYNC_STATS
/* ================================================================================= */
/* =================================================================================
*/
/**
* @file
* This file contains function prototypes of cp request and response
Expand All @@ -231,8 +228,7 @@ send_ddn_ack(struct dp_id dp_id,
/**
* Open Statstics record file.
*/
void
stats_init(void);
void stats_init(void);

/**
* Maintain stats in hash table.
Expand All @@ -242,8 +238,7 @@ stats_init(void);
* @return
* Void
*/
void
add_stats_entry(struct sync_stats *stats);
void add_stats_entry(struct sync_stats *stats);

/**
* Update the resp and ack time in hash table.
Expand All @@ -255,8 +250,7 @@ add_stats_entry(struct sync_stats *stats);
* @return
* Void
*/
void
update_stats_entry(uint64_t key, uint8_t type);
void update_stats_entry(uint64_t key, uint8_t type);

/**
* Retrive entries from stats hash table
Expand All @@ -265,8 +259,7 @@ update_stats_entry(uint64_t key, uint8_t type);
* @return
* Void
*/
void
retrive_stats_entry(void);
void retrive_stats_entry(void);

/**
* Export stats reports to file.
Expand All @@ -276,14 +269,13 @@ retrive_stats_entry(void);
* @return
* Void
*/
void
export_stats_report(struct sync_stats stats_info);
void export_stats_report(struct sync_stats stats_info);

/**
* Close current stats file and redirects any remaining output to stderr
*/
void
close_stats(void);
#endif /* SYNC_STATS */
/* ================================================================================= */
void close_stats(void);
#endif /* SYNC_STATS */
/* =================================================================================
*/
#endif
108 changes: 50 additions & 58 deletions cp/cp_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#ifdef SDN_ODL_BUILD
#include "nb.h"
Expand All @@ -30,8 +30,7 @@ struct cp_stats_t cp_stats;
* @brief callback used to display rx packets per second
* @return number of packets received by the control plane s11 interface
*/
static uint64_t
rx_pkts_per_sec(void)
static uint64_t rx_pkts_per_sec(void)
{
uint64_t ret = cp_stats.rx - cp_stats.rx_last;

Expand All @@ -43,8 +42,7 @@ rx_pkts_per_sec(void)
* @brief callback used to display tx packets per second
* @return number of packets transmitted by the control plane s11 interface
*/
static uint64_t
tx_pkts_per_sec(void)
static uint64_t tx_pkts_per_sec(void)
{
uint64_t ret = cp_stats.tx - cp_stats.tx_last;

Expand All @@ -56,8 +54,7 @@ tx_pkts_per_sec(void)
* @brief callback used to display control plane uptime
* @return control plane uptime in seconds
*/
static uint64_t
stats_time(void)
static uint64_t stats_time(void)
{
uint64_t ret = cp_stats.time;

Expand All @@ -66,16 +63,14 @@ stats_time(void)
}

#ifdef SDN_ODL_BUILD
static uint64_t
nb_ok_delta(void)
static uint64_t nb_ok_delta(void)
{
uint64_t nb_ok = cp_stats.nb_ok;
uint64_t nb_sent = cp_stats.nb_sent;
return (nb_ok < nb_sent ? nb_sent - nb_ok : 0);
}

static uint64_t
nb_cnr_delta(void)
static uint64_t nb_cnr_delta(void)
{
uint64_t nb_cnr = cp_stats.nb_cnr;
uint64_t nb_sent = cp_stats.nb_sent;
Expand All @@ -88,57 +83,59 @@ nb_cnr_delta(void)
* values or calculations and their names
*/
struct stat_entry_t {
enum {VALUE, LAMBDA} type;
uint8_t spacing; /** variable length stat entry specifier */
enum { VALUE, LAMBDA } type;
uint8_t spacing; /** variable length stat entry specifier */
union {
uint64_t *value; /** value used by stat */
uint64_t (*lambda)(void); /** stat callback function */
uint64_t *value; /** value used by stat */
uint64_t (*lambda)(void); /** stat callback function */
};
const char *top; /** top collumn stat name string */
const char *bottom; /** bottom collumn stat name string */
const char *top; /** top collumn stat name string */
const char *bottom; /** bottom collumn stat name string */
};

#define DEFINE_VALUE_STAT(spacing, function, top, bottom) \
{VALUE, spacing, {.value = function}, top, bottom}
#define DEFINE_LAMBDA_STAT(spacing, function, top, bottom) \
{LAMBDA, spacing, {.lambda = function}, top, bottom}
#define PRINT_STAT_ENTRY_HEADER(entry_index, header) \
printf("%*s ",\
stat_entries[entry_index].spacing, \
stat_entries[entry_index].header)
#define DEFINE_VALUE_STAT(spacing, function, top, bottom) \
{ \
VALUE, spacing, {.value = function}, top, bottom \
}
#define DEFINE_LAMBDA_STAT(spacing, function, top, bottom) \
{ \
LAMBDA, spacing, {.lambda = function}, top, bottom \
}
#define PRINT_STAT_ENTRY_HEADER(entry_index, header) \
printf("%*s ", stat_entries[entry_index].spacing, \
stat_entries[entry_index].header)

/**
* statistic entry definitions
*/
struct stat_entry_t stat_entries[] = {
DEFINE_LAMBDA_STAT(5, stats_time, "", "time"),
DEFINE_VALUE_STAT(8, &cp_stats.rx, "rx", "pkts"),
DEFINE_VALUE_STAT(8, &cp_stats.tx, "tx", "pkts"),
DEFINE_LAMBDA_STAT(8, rx_pkts_per_sec, "rx pkts", "/sec"),
DEFINE_LAMBDA_STAT(8, tx_pkts_per_sec, "tx pkts", "/sec"),
DEFINE_VALUE_STAT(8, &cp_stats.create_session, "create", "session"),
DEFINE_VALUE_STAT(8, &cp_stats.modify_bearer, "modify", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.bearer_resource, "b resrc", "cmd"),
DEFINE_VALUE_STAT(8, &cp_stats.create_bearer, "create", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.delete_bearer, "delete", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.delete_session, "delete", "session"),
DEFINE_VALUE_STAT(8, &cp_stats.echo, "", "echo"),
DEFINE_VALUE_STAT(8, &cp_stats.rel_access_bearer, "rel acc", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.ddn, "", "ddn"),
DEFINE_VALUE_STAT(8, &cp_stats.ddn_ack, "ddn", "ack"),
DEFINE_LAMBDA_STAT(5, stats_time, "", "time"),
DEFINE_VALUE_STAT(8, &cp_stats.rx, "rx", "pkts"),
DEFINE_VALUE_STAT(8, &cp_stats.tx, "tx", "pkts"),
DEFINE_LAMBDA_STAT(8, rx_pkts_per_sec, "rx pkts", "/sec"),
DEFINE_LAMBDA_STAT(8, tx_pkts_per_sec, "tx pkts", "/sec"),
DEFINE_VALUE_STAT(8, &cp_stats.create_session, "create", "session"),
DEFINE_VALUE_STAT(8, &cp_stats.modify_bearer, "modify", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.bearer_resource, "b resrc", "cmd"),
DEFINE_VALUE_STAT(8, &cp_stats.create_bearer, "create", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.delete_bearer, "delete", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.delete_session, "delete", "session"),
DEFINE_VALUE_STAT(8, &cp_stats.echo, "", "echo"),
DEFINE_VALUE_STAT(8, &cp_stats.rel_access_bearer, "rel acc", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.ddn, "", "ddn"),
DEFINE_VALUE_STAT(8, &cp_stats.ddn_ack, "ddn", "ack"),
#ifdef SDN_ODL_BUILD
DEFINE_VALUE_STAT(8, &cp_stats.nb_sent, "nb", "sent"),
DEFINE_LAMBDA_STAT(8, nb_ok_delta, "nb ok", "delta"),
DEFINE_LAMBDA_STAT(8, nb_cnr_delta, "nb cnr", "delta"),
DEFINE_VALUE_STAT(8, &cp_stats.nb_sent, "nb", "sent"),
DEFINE_LAMBDA_STAT(8, nb_ok_delta, "nb ok", "delta"),
DEFINE_LAMBDA_STAT(8, nb_cnr_delta, "nb cnr", "delta"),
#endif
};


/**
* @brief prints out statistics entries
*/
static inline void
print_stat_entries(void) {
static inline void print_stat_entries(void)
{
unsigned i;

if (!(cp_stats.time % 32)) {
Expand All @@ -152,17 +149,15 @@ print_stat_entries(void) {
}

for (i = 0; i < RTE_DIM(stat_entries); ++i) {
printf("%*"PRIu64" ", stat_entries[i].spacing,
(stat_entries[i].type == VALUE) ?
*stat_entries[i].value :
(*stat_entries[i].lambda)());
printf("%*" PRIu64 " ", stat_entries[i].spacing,
(stat_entries[i].type == VALUE)
? *stat_entries[i].value
: (*stat_entries[i].lambda)());
}
puts("");
}


int
do_stats(__rte_unused void *ptr)
int do_stats(__rte_unused void *ptr)
{
while (1) {
#ifdef SDN_ODL_BUILD
Expand All @@ -179,7 +174,4 @@ do_stats(__rte_unused void *ptr)
return 0;
}

void
reset_cp_stats(void) {
memset(&cp_stats, 0, sizeof(cp_stats));
}
void reset_cp_stats(void) { memset(&cp_stats, 0, sizeof(cp_stats)); }

0 comments on commit 2583b62

Please sign in to comment.