bts: Add counter availablePDCHAllocatedTime

We basically want to probe whether it's possible to allocate TBFs, or
whether we know it will fail due to all main resources being already in
use (TFI, USF).

Having bts_all_pdch_allocated() return false doesn't mean though that an
MS will be able to allocate a TBF for sure. That's because further
restrictions are applied based on MS: whether it was already attached to
a specific TRX, whether the ms_class allows for a certain multislot
combination, etc. However, it should provide a general idea on whether
for sure the PCU is unable to provide more allocations. More fine
grained state about failures can still be followed by looking at
tbf:alloc:failed:* rate counters.

Related: SYS#4878
Depends: Iabb17a08e6e1a86f168cdb008fba05ecd4776bdd (libosmocore)
Change-Id: Ie0f0c451558817bddc3fe1a0f0df531f14c9f1d3
diff --git a/src/gprs_pcu.c b/src/gprs_pcu.c
index 5ed9d7d..8b8e46b 100644
--- a/src/gprs_pcu.c
+++ b/src/gprs_pcu.c
@@ -47,8 +47,21 @@
 	{ .T=0, .default_val=0, .unit=OSMO_TDEF_S, .desc=NULL, .val=0 } /* empty item at the end */
 };
 
+static void _update_stats_timer_cb(void *data)
+{
+	struct gprs_pcu *pcu = (struct gprs_pcu *)data;
+	struct gprs_rlcmac_bts *bts;
+
+	llist_for_each_entry(bts, &pcu->bts_list, list)
+		osmo_time_cc_set_flag(&bts->all_allocated_pdch, bts_all_pdch_allocated(bts));
+
+	osmo_timer_schedule(&pcu->update_stats_timer, 1, 0);
+}
+
 static int gprs_pcu_talloc_destructor(struct gprs_pcu *pcu)
 {
+	if (osmo_timer_pending(&pcu->update_stats_timer))
+		osmo_timer_del(&pcu->update_stats_timer);
 	neigh_cache_free(pcu->neigh_cache);
 	si_cache_free(pcu->si_cache);
 	return 0;
@@ -125,6 +138,9 @@
 	pcu->neigh_cache = neigh_cache_alloc(pcu, osmo_tdef_get(pcu->T_defs, PCU_TDEF_NEIGH_CACHE_ALIVE, OSMO_TDEF_S, -1));
 	pcu->si_cache = si_cache_alloc(pcu, osmo_tdef_get(pcu->T_defs, PCU_TDEF_SI_CACHE_ALIVE, OSMO_TDEF_S, -1));
 
+	osmo_timer_setup(&pcu->update_stats_timer, _update_stats_timer_cb, pcu);
+	osmo_timer_schedule(&pcu->update_stats_timer, 1, 0);
+
 	return pcu;
 }