Skip to content

Commit

Permalink
Merge pull request #15285 from basilfx/feature/optimize_debug
Browse files Browse the repository at this point in the history
treewide: more cleanups of ENABLE_DEBUG
  • Loading branch information
basilfx authored Nov 3, 2020
2 parents a95b0c6 + 0c8df9b commit e8cadc0
Show file tree
Hide file tree
Showing 65 changed files with 479 additions and 547 deletions.
2 changes: 1 addition & 1 deletion core/priority_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj)
new_obj->next = NULL;
}

#if ENABLE_DEBUG
#if IS_ACTIVE(ENABLE_DEBUG)
void priority_queue_print(priority_queue_t *root)
{
printf("queue:\n");
Expand Down
6 changes: 1 addition & 5 deletions core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include <stdint.h>
#include <inttypes.h>

#include "sched.h"
#include "clist.h"
Expand All @@ -35,11 +36,6 @@
#define ENABLE_DEBUG 0
#include "debug.h"

#if ENABLE_DEBUG
/* For PRIu16 etc. */
#include <inttypes.h>
#endif

#ifdef PICOLIBC_TLS
#include <picotls.h>
#endif
Expand Down
14 changes: 7 additions & 7 deletions cpu/esp32/esp-eth/esp_eth_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ static int _esp_eth_send(netdev_t *netdev, const iolist_t *iolist)
}
}

#if ENABLE_DEBUG
printf ("%s: send %d byte\n", __func__, dev->tx_len);
/* esp_hexdump (dev->tx_buf, dev->tx_len, 'b', 16); */
#endif
if (IS_ACTIVE(ENABLE_DEBUG)) {
printf ("%s: send %d byte\n", __func__, dev->tx_len);
/* esp_hexdump (dev->tx_buf, dev->tx_len, 'b', 16); */
}

int ret = 0;

Expand Down Expand Up @@ -253,9 +253,9 @@ static int _esp_eth_recv(netdev_t *netdev, void *buf, size_t len, void *info)
return -ENOBUFS;
}

#if ENABLE_DEBUG
/* esp_hexdump (dev->rx_buf, dev->rx_len, 'b', 16); */
#endif
if (IS_ACTIVE(ENABLE_DEBUG)) {
esp_hexdump (dev->rx_buf, dev->rx_len, 'b', 16);
}

/* copy received date and reset the receive length */
memcpy(buf, dev->rx_buf, dev->rx_len);
Expand Down
15 changes: 8 additions & 7 deletions cpu/esp32/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,14 @@ unsigned int IRAM timer_read(tim_t dev)
{
CHECK_PARAM_RET (dev < HW_TIMER_NUMOF, -1);

#if ENABLE_DEBUG
uint32_t count_lo = timer_get_counter_lo(dev);
DEBUG("%s %u\n", __func__, count_lo);
return count_lo;
#else
return timer_get_counter_lo(dev);
#endif
if (IS_ACTIVE(ENABLE_DEBUG)) {
uint32_t count_lo = timer_get_counter_lo(dev);
DEBUG("%s %u\n", __func__, count_lo);
return count_lo;
}
else {
return timer_get_counter_lo(dev);
}
}

void IRAM timer_start(tim_t dev)
Expand Down
36 changes: 18 additions & 18 deletions cpu/esp32/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,30 @@ NORETURN void IRAM call_start_cpu0 (void)
rtc_clk_apb_freq_get(), rtc_clk_xtal_freq_get()*MHZ,
rtc_clk_slow_freq_get_hz());

#if ENABLE_DEBUG
ets_printf("reset reason: %d\n", reset_reason);
ets_printf("_stack %p\n", sp);
ets_printf("_bss_start %p\n", &_bss_start);
ets_printf("_bss_end %p\n", &_bss_end);
#ifndef MODULE_ESP_IDF_HEAP
ets_printf("_heap_start %p\n", &_sheap);
ets_printf("_heap_end %p\n", &_eheap);
ets_printf("_heap_free %u\n", get_free_heap_size());
#endif /* MODULE_ESP_IDF_HEAP */
#endif /* ENABLE_DEBUG */
if (IS_ACTIVE(ENABLE_DEBUG)) {
ets_printf("reset reason: %d\n", reset_reason);
ets_printf("_stack %p\n", sp);
ets_printf("_bss_start %p\n", &_bss_start);
ets_printf("_bss_end %p\n", &_bss_end);
if (!IS_ACTIVE(MODULE_ESP_IDF_HEAP)) {
ets_printf("_heap_start %p\n", &_sheap);
ets_printf("_heap_end %p\n", &_eheap);
ets_printf("_heap_free %u\n", get_free_heap_size());
}
}

LOG_STARTUP("PRO cpu is up (single core mode, only PRO cpu is used)\n");

/* disable APP cpu */
DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN);

#ifdef MODULE_ESP_IDF_HEAP
/* init heap */
heap_caps_init();
#if ENABLE_DEBUG
ets_printf("Heap free: %u byte\n", get_free_heap_size());
#endif /* ENABLE_DEBUG */
#endif /* MODULE_ESP_IDF_HEAP */
if (IS_ACTIVE(MODULE_ESP_IDF_HEAP)) {
/* init heap */
heap_caps_init();
if (IS_ACTIVE(ENABLE_DEBUG)) {
ets_printf("Heap free: %u byte\n", get_free_heap_size());
}
}

/* init SPI RAM if enabled */
#if CONFIG_SPIRAM_SUPPORT && CONFIG_SPIRAM_BOOT_INIT
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "esp_heap_trace.h"
#include "priv/esp_heap_caps_priv.h"

#if ENABLE_DEBUG
#if IS_ACTIVE(ENABLE_DEBUG)
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#endif

Expand Down
12 changes: 6 additions & 6 deletions cpu/esp_common/esp-now/esp_now_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ static void IRAM_ATTR esp_now_scan_peers_done(void)
critical_exit_var(state);
}

#if ENABLE_DEBUG
esp_now_peer_num_t peer_num;
esp_now_get_peer_num(&peer_num);
DEBUG("associated peers total=%d, encrypted=%d\n",
peer_num.total_num, peer_num.encrypt_num);
#endif /* ENABLE_DEBUG */
if (IS_ACTIVE(ENABLE_DEBUG)) {
esp_now_peer_num_t peer_num;
esp_now_get_peer_num(&peer_num);
DEBUG("associated peers total=%d, encrypted=%d\n",
peer_num.total_num, peer_num.encrypt_num);
}

_esp_now_scan_peers_done = true;

Expand Down
29 changes: 15 additions & 14 deletions cpu/esp_common/esp-wifi/esp_wifi_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,13 @@ static int _esp_wifi_send(netdev_t *netdev, const iolist_t *iolist)
}
}

#if ENABLE_DEBUG
ESP_WIFI_DEBUG("send %d byte", dev->tx_len);
#if MODULE_OD && ENABLE_DEBUG_HEXDUMP
od_hex_dump(dev->tx_buf, dev->tx_len, OD_WIDTH_DEFAULT);
#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */
#endif
if (IS_ACTIVE(ENABLE_DEBUG)) {
ESP_WIFI_DEBUG("send %d byte", dev->tx_len);
if (IS_ACTIVE(ENABLE_DEBUG_HEXDUMP) && IS_USED(MODULE_OD)) {
od_hex_dump(dev->tx_buf, dev->tx_len, OD_WIDTH_DEFAULT);
}
}

critical_exit();

#ifdef MODULE_ESP_WIFI_AP
Expand Down Expand Up @@ -665,15 +666,15 @@ static int _esp_wifi_recv(netdev_t *netdev, void *buf, size_t len, void *info)
ringbuffer_remove(&dev->rx_buf, sizeof(uint16_t));
ringbuffer_get(&dev->rx_buf, buf, size);

#if ENABLE_DEBUG
ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf;
if (IS_ACTIVE(ENABLE_DEBUG)) {
ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf;
ESP_WIFI_DEBUG("received %u byte from addr " MAC_STR,
size, MAC_STR_ARG(hdr->src));

ESP_WIFI_DEBUG("received %u byte from addr " MAC_STR,
size, MAC_STR_ARG(hdr->src));
#if MODULE_OD && ENABLE_DEBUG_HEXDUMP
od_hex_dump(buf, size, OD_WIDTH_DEFAULT);
#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */
#endif /* ENABLE_DEBUG */
if (IS_ACTIVE(ENABLE_DEBUG_HEXDUMP) && IS_USED(MODULE_OD)) {
od_hex_dump(buf, size, OD_WIDTH_DEFAULT);
}
}

critical_exit();
return size;
Expand Down
28 changes: 14 additions & 14 deletions cpu/esp_common/periph/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,15 @@ void IRAM_ATTR spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont,
return;
}

#if ENABLE_DEBUG
if (out) {
DEBUG("out = ");
for (size_t i = 0; i < len; i++) {
DEBUG("%02x ", ((const uint8_t *)out)[i]);
if (IS_ACTIVE(ENABLE_DEBUG)) {
if (out) {
DEBUG("out = ");
for (size_t i = 0; i < len; i++) {
DEBUG("%02x ", ((const uint8_t *)out)[i]);
}
DEBUG("\n");
}
DEBUG("\n");
}
#endif

if (cs != SPI_CS_UNDEF) {
gpio_clear(cs);
Expand Down Expand Up @@ -524,13 +524,13 @@ void IRAM_ATTR spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont,
gpio_set (cs);
}

#if ENABLE_DEBUG
if (in) {
DEBUG("in = ");
for (size_t i = 0; i < len; i++) {
DEBUG("%02x ", ((const uint8_t *)in)[i]);
if (IS_ACTIVE(ENABLE_DEBUG)) {
if (in) {
DEBUG("in = ");
for (size_t i = 0; i < len; i++) {
DEBUG("%02x ", ((const uint8_t *)in)[i]);
}
DEBUG("\n");
}
DEBUG("\n");
}
#endif
}
4 changes: 2 additions & 2 deletions cpu/native/periph/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static inline void eeprom_native_write(void)
DEBUG("Writing data to EEPROM file %s:\n", eeprom_file);
fwrite(_eeprom_buf, 1, ARRAY_SIZE(_eeprom_buf), fp);

if (ENABLE_DEBUG) {
if (IS_ACTIVE(ENABLE_DEBUG)) {
for (size_t i = 0; i < ARRAY_SIZE(_eeprom_buf); i++) {
DEBUG("0x%02X ", _eeprom_buf[i]);
if ((i + 1) % 16 == 0) {
Expand All @@ -69,7 +69,7 @@ void eeprom_native_read(void)

DEBUG("Reading data from EEPROM file %s:\n", eeprom_file);
fread(_eeprom_buf, 1, ARRAY_SIZE(_eeprom_buf), fp);
if (ENABLE_DEBUG) {
if (IS_ACTIVE(ENABLE_DEBUG)) {
for (size_t i = 0; i < ARRAY_SIZE(_eeprom_buf); i++) {
DEBUG("0x%02X ", _eeprom_buf[i]);
if ((i + 1) % 16 == 0) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/native/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len)
{
DEBUG("writing to serial port ");

if (ENABLE_DEBUG) {
if (IS_ACTIVE(ENABLE_DEBUG)) {
for (size_t i = 0; i < len; i++) {
DEBUG("%02x ", (unsigned char) data[i]);
}
Expand Down
14 changes: 7 additions & 7 deletions cpu/native/socket_zep/socket_zep.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
(unsigned)len, (void *)info);
if ((buf == NULL) || (len == 0)) {
int res = real_ioctl(dev->sock_fd, FIONREAD, &size);
#if ENABLE_DEBUG
if (res < 0) {
DEBUG("socket_zep::recv: error reading FIONREAD: %s",
strerror(errno));

if (IS_ACTIVE(ENABLE_DEBUG)) {
if (res < 0) {
DEBUG("socket_zep::recv: error reading FIONREAD: %s",
strerror(errno));
}
}
#else
(void)res;
#endif

return size;
}
else if (len > 0) {
Expand Down
17 changes: 8 additions & 9 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
#include "native_internal.h"

#define ENABLE_DEBUG 0
#if ENABLE_DEBUG
#define LOCAL_DEBUG (1)
#endif
#include "debug.h"

ssize_t (*real_read)(int fd, void *buf, size_t count);
Expand Down Expand Up @@ -109,16 +106,18 @@ int (*real_clock_gettime)(clockid_t clk_id, struct timespec *tp);
void _native_syscall_enter(void)
{
_native_in_syscall++;
#if LOCAL_DEBUG
real_write(STDERR_FILENO, "> _native_in_syscall\n", 21);
#endif

if (IS_ACTIVE(ENABLE_DEBUG)) {
real_write(STDERR_FILENO, "> _native_in_syscall\n", 21);
}
}

void _native_syscall_leave(void)
{
#if LOCAL_DEBUG
real_write(STDERR_FILENO, "< _native_in_syscall\n", 21);
#endif
if (IS_ACTIVE(ENABLE_DEBUG)) {
real_write(STDERR_FILENO, "< _native_in_syscall\n", 21);
}

_native_in_syscall--;
if (
(_native_sigpend > 0)
Expand Down
16 changes: 16 additions & 0 deletions dist/tools/coccinelle/warn/enable_debug.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ENABLE_DEBUG must not use parenthesis to be compatible with IS_ACTIVE

@@
constant C;
@@

- #define ENABLE_DEBUG (C)
+ #define ENABLE_DEBUG C

// make sure that ENABLE_DEBUG is zero

@@
@@

- #define ENABLE_DEBUG 1
+ #define ENABLE_DEBUG 0
5 changes: 0 additions & 5 deletions dist/tools/coccinelle/warn/enable_debug_false.cocci

This file was deleted.

18 changes: 9 additions & 9 deletions drivers/adt7310/adt7310.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs)
/* CS */
spi_init_cs(dev->spi, dev->cs);

#if ENABLE_DEBUG
for (int i = 0; i < 8; ++i) {
uint16_t dbg_reg = 0;
status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg);
if (status != 0) {
printf("Error reading address 0x%02x", i);
if (IS_ACTIVE(ENABLE_DEBUG)) {
for (int i = 0; i < 8; ++i) {
uint16_t dbg_reg = 0;
status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg);
if (status != 0) {
printf("Error reading address 0x%02x", i);
}
dbg_reg = htons(dbg_reg);
printf("%02x: %04" PRIx16 "\n", i, dbg_reg);
}
dbg_reg = htons(dbg_reg);
printf("%02x: %04" PRIx16 "\n", i, dbg_reg);
}
#endif

/* Read ID register from device */
status = adt7310_read_reg(dev, ADT7310_REG_ID, ADT7310_REG_SIZE_ID, &reg);
Expand Down
Loading

0 comments on commit e8cadc0

Please sign in to comment.