Skip to content

Commit cd53e32

Browse files
committed
Fully working. Just needs to be cleaned up.
1 parent 566b4b8 commit cd53e32

6 files changed

+91
-16
lines changed

include/LTE-Tracker.h

+34-11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class tracked_cell_t {
4545
crs_sp_av=NAN;
4646
crs_np_av=itpp::vec(4);
4747
crs_np_av=NAN;
48+
launched=false;
4849
}
4950
inline uint8 const n_symb_dl() const {
5051
return (cp_type==cp_type_t::NORMAL)?7:((cp_type==cp_type_t::EXTENDED)?6:-1);
@@ -67,6 +68,8 @@ class tracked_cell_t {
6768

6869
// Indicates that the tracker process is ready to receive data.
6970
bool tracker_thread_ready;
71+
// Indicates that the thread has been launched
72+
bool launched;
7073

7174
// Mutex and measurement data produced by the tracker thread and read by
7275
// the display thread.
@@ -100,7 +103,6 @@ class tracked_cell_t {
100103
// threads.
101104
boost::mutex frame_timing_mutex;
102105
double frame_timing_private;
103-
104106
};
105107
// Structure that is used to record all the tracked cells.
106108
typedef struct {
@@ -111,20 +113,12 @@ typedef struct {
111113
std::list <tracked_cell_t *> tracked_cells;
112114
} tracked_cell_list_t;
113115
// Global data shared by all threads
114-
/*
115-
typedef struct {
116-
// The frequency offset of the dongle. This value will be updated
117-
// continuously.
118-
boost::mutex frequency_offset_mutex;
119-
double frequency_offset;
120-
// This value will never change.
121-
double fc;
122-
} global_thread_data_t;
123-
*/
124116
class global_thread_data_t {
125117
public:
126118
// Constructor
127119
global_thread_data_t(const double & fc) : fc(fc) {
120+
searcher_cycle_time_private=0;
121+
cell_seconds_dropped_private=0;
128122
}
129123
// This value will never change.
130124
const double fc;
@@ -140,11 +134,40 @@ class global_thread_data_t {
140134
boost::mutex::scoped_lock lock(frequency_offset_mutex);
141135
frequency_offset_private=f;
142136
}
137+
// Read/write searcher cycle time (via mutex).
138+
// Mutex makes sure that no read or write is interrupted when
139+
// only part of the data has been read.
140+
inline double searcher_cycle_time() {
141+
boost::mutex::scoped_lock lock(searcher_cycle_time_mutex);
142+
double r=searcher_cycle_time_private;
143+
return r;
144+
}
145+
inline void searcher_cycle_time(const double & t) {
146+
boost::mutex::scoped_lock lock(searcher_cycle_time_mutex);
147+
searcher_cycle_time_private=t;
148+
}
149+
inline uint32 cell_seconds_dropped() {
150+
boost::mutex::scoped_lock lock(cell_seconds_dropped_mutex);
151+
double r=cell_seconds_dropped_private;
152+
return r;
153+
}
154+
inline void cell_seconds_dropped_inc() {
155+
boost::mutex::scoped_lock lock(cell_seconds_dropped_mutex);
156+
cell_seconds_dropped_private+=1;
157+
}
158+
uint32 searcher_thread_id;
159+
uint32 producer_thread_id;
160+
uint32 main_thread_id;
161+
uint32 display_thread_id;
143162
private:
144163
// The frequency offset of the dongle. This value will be updated
145164
// continuously.
146165
boost::mutex frequency_offset_mutex;
147166
double frequency_offset_private;
167+
boost::mutex searcher_cycle_time_mutex;
168+
double searcher_cycle_time_private;
169+
boost::mutex cell_seconds_dropped_mutex;
170+
uint32 cell_seconds_dropped_private;
148171
};
149172
// IPC between main thread and searcher thread covering data capture issues.
150173
typedef struct {

src/LTE-Tracker.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <signal.h>
3030
#include <queue>
3131
#include <sys/stat.h>
32+
#include <sys/syscall.h>
33+
#include <sys/types.h>
3234
#include "rtl-sdr.h"
3335
#include "common.h"
3436
#include "macros.h"
@@ -895,6 +897,7 @@ int main(
895897
tracked_cell_list_t tracked_cell_list;
896898
capbuf_sync_t capbuf_sync;
897899
global_thread_data_t global_thread_data(fc);
900+
global_thread_data.main_thread_id=syscall(SYS_gettid);
898901

899902
// Calibrate the dongle's oscillator. This is similar to running the
900903
// program CellSearch with only one center frequency. All information

src/display_thread.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <signal.h>
3030
#include <queue>
3131
#include <curses.h>
32+
#include <sys/syscall.h>
33+
#include <sys/types.h>
3234
#include "rtl-sdr.h"
3335
#include "common.h"
3436
#include "macros.h"
@@ -51,6 +53,8 @@ void display_thread(
5153
global_thread_data_t & global_thread_data,
5254
tracked_cell_list_t & tracked_cell_list
5355
) {
56+
global_thread_data.display_thread_id=syscall(SYS_gettid);
57+
5458
initscr();
5559
// What does this do?
5660
(void)echo();
@@ -67,8 +71,15 @@ void display_thread(
6771
{
6872
boost::mutex::scoped_lock lock(sampbuf_sync.mutex);
6973
//cout << "Raw sample buffer size: " << sampbuf_sync.fifo.size() << "/" << sampbuf_sync.fifo_peak_size << endl;
70-
printw(" Raw buffer status: %6li/%6li\n\n",sampbuf_sync.fifo.size(),sampbuf_sync.fifo_peak_size);
74+
printw(" Raw buffer status: %6li/%6li\n",sampbuf_sync.fifo.size(),sampbuf_sync.fifo_peak_size);
7175
}
76+
printw("Searcher cycle time: %.1lf s\n\n",global_thread_data.searcher_cycle_time());
77+
printw("Searcher thread ID: %5i\n",global_thread_data.searcher_thread_id);
78+
printw("Producer thread ID: %5i\n",global_thread_data.producer_thread_id);
79+
printw("Main thread ID: %5i\n",global_thread_data.main_thread_id);
80+
printw("Display thread ID: %5i\n\n",global_thread_data.display_thread_id);
81+
82+
printw("Cell seconds dropped: %i\n\n",global_thread_data.cell_seconds_dropped());
7283

7384
{
7485
boost::mutex::scoped_lock lock(tracked_cell_list.mutex);

src/producer_thread.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <sstream>
2929
#include <signal.h>
3030
#include <queue>
31+
#include <sys/syscall.h>
32+
#include <sys/types.h>
3133
#include "rtl-sdr.h"
3234
#include "common.h"
3335
#include "macros.h"
@@ -61,6 +63,8 @@ void producer_thread(
6163
tracked_cell_list_t & tracked_cell_list,
6264
double & fc
6365
) {
66+
global_thread_data.producer_thread_id=syscall(SYS_gettid);
67+
6468
// Main loop which distributes data to the appropriate subthread.
6569
// Local storage for each cell.
6670
cell_local_t cell_local[504];
@@ -155,6 +159,11 @@ void producer_thread(
155159
list <tracked_cell_t *>::iterator it=tracked_cell_list.tracked_cells.begin();
156160
while (it!=tracked_cell_list.tracked_cells.end()) {
157161
tracked_cell_t & tracked_cell=(*(*it));
162+
// See if this thread has been launched yet. If not, launch it.
163+
if (!tracked_cell.launched) {
164+
tracked_cell.thread=boost::thread(tracker_thread,boost::ref(tracked_cell),boost::ref(global_thread_data));
165+
tracked_cell.launched=true;
166+
}
158167
double frame_timing=tracked_cell.frame_timing();
159168

160169
cell_local_t & cl=cell_local[tracked_cell.n_id_cell];

src/searcher_thread.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <signal.h>
3030
#include <queue>
3131
#include <valgrind/callgrind.h>
32+
#include <sys/syscall.h>
33+
#include <sys/types.h>
3234
#include "rtl-sdr.h"
3335
#include "common.h"
3436
#include "macros.h"
@@ -58,7 +60,9 @@ void searcher_thread(
5860
cout << "Searcher process has been launched." << endl;
5961
}
6062

61-
if (nice(10)==-1) {
63+
global_thread_data.searcher_thread_id=syscall(SYS_gettid);
64+
65+
if (nice(20)==-1) {
6266
cerr << "Error: could not reduce searcher process priority" << endl;
6367
exit(-1);
6468
}
@@ -72,7 +76,11 @@ void searcher_thread(
7276
const double & fc=global_thread_data.fc;
7377

7478
// Loop forever.
79+
Real_Timer tt;
7580
while (true) {
81+
// Used to measure searcher cycle time.
82+
tt.tic();
83+
7684
// Request data.
7785
{
7886
boost::mutex::scoped_lock lock(capbuf_sync.mutex);
@@ -209,17 +217,25 @@ void searcher_thread(
209217
//tracked_cell_t * new_cell = new tracked_cell_t((*iterator).n_id_cell(),(*iterator).n_ports,(*iterator).cp_type,(*iterator).frame_start/k_factor+capbuf_sync.late+global_1);
210218
tracked_cell_t * new_cell = new tracked_cell_t((*iterator).n_id_cell(),(*iterator).n_ports,(*iterator).cp_type,(*iterator).frame_start/k_factor+capbuf_sync.late,serial_num((*iterator).n_id_cell()));
211219
serial_num((*iterator).n_id_cell())++;
212-
(*new_cell).thread=boost::thread(tracker_thread,boost::ref(*new_cell),boost::ref(global_thread_data));
220+
// Cannot launch thread here. If thread was launched here, it would
221+
// have the same (low) priority as the searcher thread.
222+
//(*new_cell).thread=boost::thread(tracker_thread,boost::ref(*new_cell),boost::ref(global_thread_data));
213223
{
214224
boost::mutex::scoped_lock lock(tracked_cell_list.mutex);
215225
tracked_cell_list.tracked_cells.push_back(new_cell);
216226
}
217227
CALLGRIND_START_INSTRUMENTATION;
218-
//cout << "Only one cell is allowed to be detected!!!" << endl;
219-
//sleep(1000000);
228+
#define MAX_DETECTED 500000
229+
static uint32 n_found=0;
230+
n_found++;
231+
if (n_found==MAX_DETECTED) {
232+
cout << "Searcher thread has stopped!" << endl;
233+
sleep(1000000);
234+
}
220235

221236
++iterator;
222237
}
238+
global_thread_data.searcher_cycle_time(tt.toc());
223239
}
224240
// Will never reach here...
225241
}

src/tracker_thread.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,19 @@ void tracker_thread(
700700
//}
701701
// Each iteration of this loop processes one OFDM symbol.
702702
while (true) {
703+
// If there is more than 1.5s worth of data in the fifo, dump
704+
// data to allow the tracker threads to catch up.
705+
{
706+
boost::mutex::scoped_lock lock(tracked_cell.fifo_mutex);
707+
uint16 n_ofdm_1s=(tracked_cell.cp_type==cp_type_t::NORMAL)?(7*2*1000):(6*2*1000);
708+
while (tracked_cell.fifo.size()>n_ofdm_1s*1.5) {
709+
for (uint32 t=0;t<n_ofdm_1s;t++) {
710+
tracked_cell.fifo.pop();
711+
}
712+
global_thread_data.cell_seconds_dropped_inc();
713+
}
714+
}
715+
703716
// Get the next frequency domain sample from the fifo.
704717
cvec syms;
705718
double frequency_offset;

0 commit comments

Comments
 (0)