fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/30101 )


Change subject: trxcon: reorganize the core logic into libtrxcon.la
......................................................................

trxcon: reorganize the core logic into libtrxcon.la

This is needed for the integration with osmo-trx-ms.  It was decided
to run the scheduler within the transceiver process, so that we can
reduce scheduling latency.  The idea is to link osmo-trx-ms against
the libtrxcon, which will evolve into the libosmo-trxcon.so soon.

We cannot use hard-coded logging categoris in a library, so add new
API for setting them: trxcon_set_log_cfg().  Use DLGLOBAL by default.

Change-Id: Idf207947f620a7394e0a0e5bf2c37bcd8df64bbe
Related: OS#5599
---
M src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
M src/host/trxcon/src/Makefile.am
M src/host/trxcon/src/l1ctl.c
M src/host/trxcon/src/logging.c
M src/host/trxcon/src/trxcon_fsm.c
M src/host/trxcon/src/trxcon_inst.c
M src/host/trxcon/src/trxcon_main.c
7 files changed, 91 insertions(+), 44 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/01/30101/1

diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h 
b/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
index e5ba5ec..9dae606 100644
--- a/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
+++ b/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
@@ -31,6 +31,16 @@
        } l1p;
 };

+struct trxcon_log_cfg {
+       int fsm; /* trxcon_fsm */
+       int l1c; /* L1CTL control */
+       int l1d; /* L1CTL data */
+       int schc; /* l1sched control */
+       int schd; /* l1sched data */
+};
+
+void trxcon_set_log_cfg(const struct trxcon_log_cfg *cfg);
+
 struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id, uint32_t 
fn_advance);
 void trxcon_inst_free(struct trxcon_inst *trxcon);

diff --git a/src/host/trxcon/src/Makefile.am b/src/host/trxcon/src/Makefile.am
index e0dc337..e0ce6a2 100644
--- a/src/host/trxcon/src/Makefile.am
+++ b/src/host/trxcon/src/Makefile.am
@@ -35,20 +35,30 @@
        $(NULL)


+noinst_LTLIBRARIES += libtrxcon.la
+
+libtrxcon_la_SOURCES = \
+       trxcon_inst.c \
+       trxcon_fsm.c \
+       l1ctl.c \
+       $(NULL)
+
+libtrxcon_la_LIBADD = \
+       libl1sched.la \
+       $(LIBOSMOCORE_LIBS) \
+       $(LIBOSMOGSM_LIBS) \
+       $(NULL)
+
+
 bin_PROGRAMS = trxcon

 trxcon_SOURCES = \
        l1ctl_server.c \
-       l1ctl.c \
-       trx_if.c \
-       logging.c \
-       trxcon_fsm.c \
-       trxcon_inst.c \
        trxcon_main.c \
+       logging.c \
+       trx_if.c \
        $(NULL)

 trxcon_LDADD = \
-       libl1sched.la \
-       $(LIBOSMOCORE_LIBS) \
-       $(LIBOSMOGSM_LIBS) \
+       libtrxcon.la \
        $(NULL)
diff --git a/src/host/trxcon/src/l1ctl.c b/src/host/trxcon/src/l1ctl.c
index 17c136a..47998d6 100644
--- a/src/host/trxcon/src/l1ctl.c
+++ b/src/host/trxcon/src/l1ctl.c
@@ -32,6 +32,7 @@
 #include <osmocom/core/fsm.h>
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/talloc.h>
+#include <osmocom/core/logging.h>

 #include <osmocom/gsm/gsm0502.h>
 #include <osmocom/gsm/gsm_utils.h>
@@ -45,6 +46,10 @@
 #define L1CTL_LENGTH           256
 #define L1CTL_HEADROOM         32

+/* Logging categories configurable via trxcon_set_log_cfg() */
+int g_logc_l1c = DLGLOBAL;
+int g_logc_l1d = DLGLOBAL;
+
 static const char *arfcn2band_name(uint16_t arfcn)
 {
        enum gsm_band band;
@@ -67,7 +72,7 @@
        msg = msgb_alloc_headroom(L1CTL_LENGTH + L1CTL_HEADROOM,
                                  L1CTL_HEADROOM, "l1ctl_tx_msg");
        if (!msg) {
-               LOGP(DL1C, LOGL_ERROR, "Failed to allocate memory\n");
+               LOGP(g_logc_l1c, LOGL_ERROR, "Failed to allocate memory\n");
                return NULL;
        }

@@ -88,7 +93,7 @@
        if (!msg)
                return -ENOMEM;

-       LOGPFSMSL(fi, DL1C, LOGL_DEBUG,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_DEBUG,
                  "Send PM Conf (%s %d = %d dBm)\n",
                  arfcn2band_name(band_arfcn),
                  band_arfcn & ~ARFCN_FLAG_MASK, dbm);
@@ -116,7 +121,7 @@
        if (!msg)
                return -ENOMEM;

-       LOGPFSMSL(fi, DL1C, LOGL_DEBUG, "Send Reset Ind (%u)\n", type);
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_DEBUG, "Send Reset Ind (%u)\n", type);

        res = (struct l1ctl_reset *) msgb_put(msg, sizeof(*res));
        res->type = type;
@@ -134,7 +139,7 @@
        if (!msg)
                return -ENOMEM;

-       LOGPFSMSL(fi, DL1C, LOGL_DEBUG, "Send Reset Conf (%u)\n", type);
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_DEBUG, "Send Reset Conf (%u)\n", type);
        res = (struct l1ctl_reset *) msgb_put(msg, sizeof(*res));
        res->type = type;

@@ -183,7 +188,7 @@

        fbsb_conf_make(msg, 255, 0);

-       LOGPFSMSL(fi, DL1C, LOGL_DEBUG, "Send FBSB Conf (timeout)\n");
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_DEBUG, "Send FBSB Conf (timeout)\n");

        return trxcon_l1ctl_send(trxcon, msg);
 }
@@ -209,7 +214,7 @@
        /* FIXME: set proper value */
        conf->initial_freq_err = 0;

-       LOGPFSMSL(fi, DL1C, LOGL_DEBUG,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_DEBUG,
                  "Send FBSB Conf (result=%u, bsic=%u)\n",
                  conf->result, conf->bsic);
 
@@ -323,7 +328,7 @@
                return GSM_PCHAN_CCCH_SDCCH4_CBCH;

        default:
-               LOGP(DL1C, LOGL_NOTICE, "Undandled CCCH mode (%u), "
+               LOGP(g_logc_l1c, LOGL_NOTICE, "Undandled CCCH mode (%u), "
                        "assuming non-combined configuration\n", mode);
                return GSM_PCHAN_CCCH;
        }
@@ -337,7 +342,7 @@

        fbsb = (struct l1ctl_fbsb_req *) msg->l1h;
        if (msgb_l1len(msg) < sizeof(*fbsb)) {
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "MSG too short FBSB Req: %u\n",
                          msgb_l1len(msg));
                rc = -EINVAL;
@@ -350,7 +355,7 @@
                .band_arfcn = ntohs(fbsb->band_arfcn),
        };

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "Received FBSB request (%s %d, timeout %u ms)\n",
                  arfcn2band_name(req.band_arfcn),
                  req.band_arfcn & ~ARFCN_FLAG_MASK,
@@ -371,7 +376,7 @@

        pmr = (struct l1ctl_pm_req *) msg->l1h;
        if (msgb_l1len(msg) < sizeof(*pmr)) {
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "MSG too short PM Req: %u\n",
                          msgb_l1len(msg));
                rc = -EINVAL;
@@ -383,7 +388,7 @@
                .band_arfcn_stop = ntohs(pmr->range.band_arfcn_to),
        };

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "Received power measurement request (%s: %d -> %d)\n",
                  arfcn2band_name(req.band_arfcn_start),
                  req.band_arfcn_start & ~ARFCN_FLAG_MASK,
@@ -404,14 +409,14 @@

        res = (struct l1ctl_reset *) msg->l1h;
        if (msgb_l1len(msg) < sizeof(*res)) {
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "MSG too short Reset Req: %u\n",
                          msgb_l1len(msg));
                rc = -EINVAL;
                goto exit;
        }

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "Received reset request (%u)\n", res->type);

        switch (res->type) {
@@ -422,7 +427,7 @@
                osmo_fsm_inst_dispatch(fi, TRXCON_EV_RESET_SCHED_REQ, NULL);
                break;
        default:
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "Unknown L1CTL_RESET_REQ type\n");
                goto exit;
        }
@@ -440,8 +445,8 @@
        struct osmo_fsm_inst *fi = trxcon->fi;
        struct l1ctl_hdr *l1h;

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE, "Recv Echo Req\n");
-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE, "Send Echo Conf\n");
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE, "Recv Echo Req\n");
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE, "Send Echo Conf\n");

        /* Nothing to do, just send it back */
        l1h = (struct l1ctl_hdr *) msg->l1h;
@@ -459,14 +464,14 @@

        mode_req = (struct l1ctl_ccch_mode_req *)msg->l1h;
        if (msgb_l1len(msg) < sizeof(*mode_req)) {
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "MSG too short Reset Req: %u\n",
                          msgb_l1len(msg));
                rc = -EINVAL;
                goto exit;
        }

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE, "Received CCCH mode request (%u)\n",
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE, "Received CCCH mode request 
(%u)\n",
                  mode_req->ccch_mode); /* TODO: add value-string for ccch_mode 
*/

        struct trxcon_param_set_ccch_tch_mode_req req = {
@@ -501,7 +506,7 @@
                        .is_11bit = true,
                };

-               LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                          "Received 11-bit RACH request "
                          "(offset=%u, synch_seq=%u, ra11=0x%02hx)\n",
                          req.offset, req.synch_seq, req.ra);
@@ -513,7 +518,7 @@
                        .ra = rr->ra,
                };

-               LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                          "Received 8-bit RACH request "
                          "(offset=%u, ra=0x%02x)\n", req.offset, req.ra);
        }
@@ -521,7 +526,7 @@
        /* The controlling L1CTL side always does include the UL info header,
         * but may leave it empty. We assume RACH is on TS0 in this case. */
        if (ul->chan_nr == 0x00) {
-               LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                          "The UL info header is empty, assuming RACH is on 
TS0\n");
                req.chan_nr = RSL_CHAN_RACH;
                req.link_id = 0x00;
@@ -542,7 +547,7 @@
 {
        req->h0.band_arfcn = ntohs(h->band_arfcn);

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "L1CTL_DM_EST_REQ indicates single ARFCN %s %u\n",
                  arfcn2band_name(req->h0.band_arfcn),
                  req->h0.band_arfcn & ~ARFCN_FLAG_MASK);
@@ -556,18 +561,18 @@
 {
        unsigned int i;

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "L1CTL_DM_EST_REQ indicates a Frequency "
                  "Hopping (hsn=%u, maio=%u, chans=%u) channel\n",
                  h->hsn, h->maio, h->n);

        /* No channels?!? */
        if (!h->n) {
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "No channels in mobile allocation?!?\n");
                return -EINVAL;
        } else if (h->n > ARRAY_SIZE(h->ma)) {
-               LOGPFSMSL(fi, DL1C, LOGL_ERROR,
+               LOGPFSMSL(fi, g_logc_l1c, LOGL_ERROR,
                          "More than 64 channels in mobile allocation?!?\n");
                return -EINVAL;
        }
@@ -599,7 +604,7 @@
                .hopping = est_req->h,
        };

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "Received L1CTL_DM_EST_REQ "
                  "(tn=%u, chan_nr=0x%02x, tsc=%u, tch_mode=0x%02x)\n",
                  req.chan_nr & 0x07, req.chan_nr, req.tsc, req.tch_mode);
@@ -623,7 +628,7 @@
 {
        struct osmo_fsm_inst *fi = trxcon->fi;

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE, "Received L1CTL_DM_REL_REQ\n");
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE, "Received L1CTL_DM_REL_REQ\n");

        osmo_fsm_inst_dispatch(fi, TRXCON_EV_DEDICATED_RELEASE_REQ, NULL);

@@ -651,7 +656,7 @@
                .data = ul->payload,
        };

-       LOGPFSMSL(fi, DL1D, LOGL_DEBUG,
+       LOGPFSMSL(fi, g_logc_l1d, LOGL_DEBUG,
                  "Recv %s Req (chan_nr=0x%02x, link_id=0x%02x, len=%zu)\n",
                  traffic ? "TRAFFIC" : "DATA", req.chan_nr, req.link_id, 
req.data_len);

@@ -678,7 +683,7 @@
        ul = (struct l1ctl_info_ul *) msg->l1h;
        par_req = (struct l1ctl_par_req *) ul->payload;

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "Received L1CTL_PARAM_REQ (ta=%d, tx_power=%u)\n",
                  par_req->ta, par_req->tx_power);

@@ -704,7 +709,7 @@

        mode_req = (struct l1ctl_tch_mode_req *)msg->l1h;

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "Received L1CTL_TCH_MODE_REQ (tch_mode=%u, audio_mode=%u)\n",
                  mode_req->tch_mode, mode_req->audio_mode);

@@ -747,7 +752,7 @@
                .key = cr->key,
        };

-       LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
+       LOGPFSMSL(fi, g_logc_l1c, LOGL_NOTICE,
                  "L1CTL_CRYPTO_REQ (algo=A5/%u, key_len=%u)\n",
                  req.a5_algo, req.key_len);

@@ -800,13 +805,13 @@
        case L1CTL_TBF_CFG_REQ:
        case L1CTL_DM_FREQ_REQ:
        case L1CTL_SIM_REQ:
-               LOGPFSMSL(trxcon->fi, DL1C, LOGL_NOTICE,
+               LOGPFSMSL(trxcon->fi, g_logc_l1c, LOGL_NOTICE,
                          "Ignoring unsupported message (type=%u)\n",
                          l1h->msg_type);
                msgb_free(msg);
                return -ENOTSUP;
        default:
-               LOGPFSMSL(trxcon->fi, DL1C, LOGL_ERROR, "Unknown MSG type %u: 
%s\n",
+               LOGPFSMSL(trxcon->fi, g_logc_l1c, LOGL_ERROR, "Unknown MSG type 
%u: %s\n",
                          l1h->msg_type, osmo_hexdump(msgb_data(msg), 
msgb_length(msg)));
                msgb_free(msg);
                return -EINVAL;
diff --git a/src/host/trxcon/src/logging.c b/src/host/trxcon/src/logging.c
index 747b1ad..f5fdacc 100644
--- a/src/host/trxcon/src/logging.c
+++ b/src/host/trxcon/src/logging.c
@@ -21,6 +21,7 @@
 #include <osmocom/core/logging.h>
 #include <osmocom/core/utils.h>

+#include <osmocom/bb/trxcon/trxcon.h>
 #include <osmocom/bb/trxcon/logging.h>

 static struct log_info_cat trxcon_log_info_cat[] = {
@@ -80,5 +81,15 @@
        if (category_mask)
                log_parse_category_mask(osmo_stderr_target, category_mask);

+       const struct trxcon_log_cfg cfg = {
+               .fsm = DAPP,
+               .l1c = DL1C,
+               .l1d = DL1D,
+               .schc = DSCH,
+               .schd = DSCHD,
+       };
+
+       trxcon_set_log_cfg(&cfg);
+
        return 0;
 }
diff --git a/src/host/trxcon/src/trxcon_fsm.c b/src/host/trxcon/src/trxcon_fsm.c
index 28a4ecb..9980344 100644
--- a/src/host/trxcon/src/trxcon_fsm.c
+++ b/src/host/trxcon/src/trxcon_fsm.c
@@ -26,11 +26,11 @@
 #include <osmocom/core/fsm.h>
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/talloc.h>
+#include <osmocom/core/logging.h>

 #include <osmocom/bb/trxcon/trxcon.h>
 #include <osmocom/bb/trxcon/trxcon_fsm.h>
 #include <osmocom/bb/trxcon/phyif.h>
-#include <osmocom/bb/trxcon/logging.h>
 #include <osmocom/bb/trxcon/l1ctl.h>
 #include <osmocom/bb/l1sched/l1sched.h>
 #include <osmocom/bb/l1sched/logging.h>
@@ -649,7 +649,7 @@
        .name = "trxcon",
        .states = trxcon_fsm_states,
        .num_states = ARRAY_SIZE(trxcon_fsm_states),
-       .log_subsys = DAPP,
+       .log_subsys = DLGLOBAL,
        .event_names = trxcon_fsm_event_names,
        .allstate_event_mask = S(TRXCON_EV_PHYIF_FAILURE)
                             | S(TRXCON_EV_L2IF_FAILURE)
diff --git a/src/host/trxcon/src/trxcon_inst.c 
b/src/host/trxcon/src/trxcon_inst.c
index c3a85da..5d96021 100644
--- a/src/host/trxcon/src/trxcon_inst.c
+++ b/src/host/trxcon/src/trxcon_inst.c
@@ -26,6 +26,18 @@
 #include <osmocom/bb/trxcon/trxcon.h>
 #include <osmocom/bb/trxcon/trxcon_fsm.h>
 #include <osmocom/bb/l1sched/l1sched.h>
+#include <osmocom/bb/l1sched/logging.h>
+
+extern int g_logc_l1c;
+extern int g_logc_l1d;
+
+void trxcon_set_log_cfg(const struct trxcon_log_cfg *cfg)
+{
+       l1sched_logging_init(cfg->schc, cfg->schd);
+       trxcon_fsm_def.log_subsys = cfg->fsm;
+       g_logc_l1c = cfg->l1c;
+       g_logc_l1d = cfg->l1d;
+}

 struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id, uint32_t 
fn_advance)
 {
diff --git a/src/host/trxcon/src/trxcon_main.c 
b/src/host/trxcon/src/trxcon_main.c
index 1ed2f89..94deeab 100644
--- a/src/host/trxcon/src/trxcon_main.c
+++ b/src/host/trxcon/src/trxcon_main.c
@@ -543,7 +543,6 @@

        /* Init logging system */
        trxcon_logging_init(tall_trxcon_ctx, app_data.debug_mask);
-       l1sched_logging_init(DSCH, DSCHD);

        /* Configure pretty logging */
        log_set_print_extended_timestamp(osmo_stderr_target, 1);

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30101
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Idf207947f620a7394e0a0e5bf2c37bcd8df64bbe
Gerrit-Change-Number: 30101
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanits...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to