From 7b1ede32b10d1ceca19fd78eb4785bb0ed935666 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 4 Aug 2020 11:58:20 +0200 Subject: [PATCH] m3: optimizing 1g and 10g digitizing by setting number of packets depending on 10/1g, dr and #counters --- .../mythen3DetectorServer/RegisterDefs.h | 11 +++ .../slsDetectorFunctionList.c | 87 ++++++++++++++----- .../include/slsDetectorFunctionList.h | 3 +- slsReceiverSoftware/src/GeneralData.h | 4 - slsReceiverSoftware/src/Implementation.cpp | 22 ++--- 5 files changed, 90 insertions(+), 37 deletions(-) diff --git a/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h b/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h index 184485b8e..da52bdc9b 100644 --- a/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h +++ b/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h @@ -152,6 +152,17 @@ #define PKT_CONFIG_1G_INTERFACE_OFST (16) #define PKT_CONFIG_1G_INTERFACE_MSK (0x00000001 << PKT_CONFIG_1G_INTERFACE_OFST) +#define PKT_FRAG_REG (0x01 * REG_OFFSET + BASE_PKT) + +#define PKT_FRAG_1G_N_DSR_PER_PKT_OFST (0) +#define PKT_FRAG_1G_N_DSR_PER_PKT_MSK (0x0000003F << PKT_FRAG_1G_N_DSR_PER_PKT_OFST) +#define PKT_FRAG_10G_N_DSR_PER_PKT_OFST (8) +#define PKT_FRAG_10G_N_DSR_PER_PKT_MSK (0x0000003F << PKT_FRAG_10G_N_DSR_PER_PKT_OFST) +#define PKT_FRAG_1G_NUM_PACKETS_OFST (16) +#define PKT_FRAG_1G_NUM_PACKETS_MSK (0x0000003F << PKT_FRAG_1G_NUM_PACKETS_OFST) +#define PKT_FRAG_10G_NUM_PACKETS_OFST (24) +#define PKT_FRAG_10G_NUM_PACKETS_MSK (0x0000003F << PKT_FRAG_10G_NUM_PACKETS_OFST) + /* Module Coordinates Register */ #define COORD_0_REG (0x02 * REG_OFFSET + BASE_PKT) #define COORD_ROW_OFST (0) diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 7a80fb20a..3f7bc8c1f 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -409,6 +409,9 @@ void setupDetector() { setDefaultDacs(); setASICDefaults(); + // no roi for 1g and 10g + setumberOfDeserializers(MAX_NUM_DESERIALIZERS, 0); + setumberOfDeserializers(MAX_NUM_DESERIALIZERS, 1); // dynamic range setDynamicRange(DEFAULT_DYNAMIC_RANGE); // enable all counters @@ -552,7 +555,7 @@ int setDynamicRange(int dr) { // set it bus_w(CONFIG_REG, bus_r(CONFIG_REG) & ~CONFIG_DYNAMIC_RANGE_MSK); bus_w(CONFIG_REG, bus_r(CONFIG_REG) | regval); - updateNumberOfDeserializers(); + updateNumberOfPackets(); } uint32_t regval = bus_r(CONFIG_REG) & CONFIG_DYNAMIC_RANGE_MSK; @@ -1033,7 +1036,7 @@ void setCounterMask(uint32_t arg) { CONFIG_COUNTERS_ENA_MSK)); LOG(logDEBUG, ("Config Reg: 0x%x\n", bus_r(addr))); - updateNumberOfDeserializers(); + updateNumberOfPackets(); updateGatePeriod(); } @@ -1041,33 +1044,59 @@ uint32_t getCounterMask() { return ((bus_r(CONFIG_REG) & CONFIG_COUNTERS_ENA_MSK) >> CONFIG_COUNTERS_ENA_OFST); } +void setumberOfDeserializers(int val, int tgEnable) { + const uint32_t addr = PKT_FRAG_REG; + LOG(logINFO, ("Setting Number of deserializers per packet: %d for %s\n", + val, (tgEnable ? "10g" : "1g"))); + if (tgEnable) { + bus_w(addr, bus_r(addr) & ~PKT_FRAG_10G_N_DSR_PER_PKT_MSK); + bus_w(addr, bus_r(addr) | ((val << PKT_FRAG_10G_N_DSR_PER_PKT_OFST) & + PKT_FRAG_10G_N_DSR_PER_PKT_MSK)); + } else { + bus_w(addr, bus_r(addr) & ~PKT_FRAG_1G_N_DSR_PER_PKT_MSK); + bus_w(addr, bus_r(addr) | ((val << PKT_FRAG_1G_N_DSR_PER_PKT_OFST) & + PKT_FRAG_1G_N_DSR_PER_PKT_MSK)); + } +} -void updateNumberOfDeserializers() { - const uint32_t counterMask = getCounterMask(); - const int ncounters = __builtin_popcount(counterMask); +void updateNumberOfPackets() { + const uint32_t addr = PKT_FRAG_REG; + const int ncounters = __builtin_popcount(getCounterMask()); const int dr = setDynamicRange(-1); const int tgEnable = enableTenGigabitEthernet(-1); + const int imageSize = calculateDataBytes(); int packetsPerFrame = 0; // 10g if (tgEnable) { packetsPerFrame = 1; - if (dr == 32 && n > 1) { + if (dr == 32 && ncounters > 1) { packetsPerFrame = 2; } } // 1g else { - int datasize = 1280; - if (n == 3) { + int dataSize = 1280; + if (ncounters == 3) { dataSize = 768; } packetsPerFrame = imageSize / dataSize; } - int numDeserializers = MAX_NUM_DESERIALIZERS / packetsPerFrame; // bus_w() - LOG(logINFO, ("Number of Deserializers: %d\n", numDeserializers)); + LOG(logINFO, ("Number of Packets/Frame: %d for %s\n", packetsPerFrame, + (tgEnable ? "10g" : "1g"))); + if (tgEnable) { + bus_w(addr, bus_r(addr) & ~PKT_FRAG_10G_NUM_PACKETS_MSK); + bus_w(addr, bus_r(addr) | + ((packetsPerFrame << PKT_FRAG_10G_NUM_PACKETS_OFST) & + PKT_FRAG_10G_NUM_PACKETS_MSK)); + } else { + bus_w(addr, bus_r(addr) & ~PKT_FRAG_1G_NUM_PACKETS_MSK); + bus_w(addr, + bus_r(addr) | ((packetsPerFrame << PKT_FRAG_1G_NUM_PACKETS_OFST) & + PKT_FRAG_1G_NUM_PACKETS_MSK)); + } } int setDelayAfterTrigger(int64_t val) { @@ -1539,7 +1568,7 @@ int enableTenGigabitEthernet(int val) { else { bus_w(addr, bus_r(addr) & (~PKT_CONFIG_1G_INTERFACE_MSK)); } - updateNumberOfDeserializers(); + updateNumberOfPackets(); } int oneG = ((bus_r(addr) & PKT_CONFIG_1G_INTERFACE_MSK) >> PKT_CONFIG_1G_INTERFACE_OFST); @@ -2090,24 +2119,38 @@ void *start_timer(void *arg) { const int numFrames = (getNumFrames() * getNumTriggers()); const int64_t expUs = getGatePeriod() / 1000; - const int imagesize = calculateDataBytes(); + const int imageSize = calculateDataBytes(); const int tgEnable = enableTenGigabitEthernet(-1); - const int packetsPerFrame = - tgEnable ? PACKETS_PER_FRAME_10G : PACKETS_PER_FRAME_1G; - const int dataSize = imagesize / packetsPerFrame; + const int dr = setDynamicRange(-1); + int ncounters = __builtin_popcount(getCounterMask()); + int dataSize = 0; + int packetsPerFrame = 0; + // 10g + if (tgEnable) { + packetsPerFrame = 1; + if (dr == 32 && ncounters > 1) { + packetsPerFrame = 2; + } + } + // 1g + else { + dataSize = 1280; + if (ncounters == 3) { + dataSize = 768; + } + packetsPerFrame = imageSize / dataSize; + } const int packetSize = dataSize + sizeof(sls_detector_header); LOG(logDEBUG1, - ("imagesize:%d tg:%d packets/Frame:%d datasize:%d packetSize:%d\n", - imagesize, tgEnable, packetsPerFrame, dataSize, packetSize)); + ("imageSize:%d tg:%d packets/Frame:%d datasize:%d packetSize:%d\n", + imageSize, tgEnable, packetsPerFrame, dataSize, packetSize)); // Generate data - char imageData[imagesize]; - memset(imageData, 0, imagesize); + char imageData[imageSize]; + memset(imageData, 0, imageSize); { - const int dr = setDynamicRange(-1); - const int numCounters = __builtin_popcount(getCounterMask()); - const int nchannels = NCHAN_1_COUNTER * NCHIP * numCounters; + const int nchannels = NCHAN_1_COUNTER * NCHIP * ncounters; switch (dr) { /*case 1: // TODO: Not implemented in firmware yet diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index c81757d0d..c552b24a2 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -250,7 +250,8 @@ int getNumDigitalSamples(); #ifdef MYTHEN3D void setCounterMask(uint32_t arg); uint32_t getCounterMask(); -void updateNumberOfDeserializers(); +void setumberOfDeserializers(int val, int tgEnable); +void updateNumberOfPackets(); #endif #if defined(JUNGFRAUD) || defined(GOTTHARDD) || defined(CHIPTESTBOARDD) || \ diff --git a/slsReceiverSoftware/src/GeneralData.h b/slsReceiverSoftware/src/GeneralData.h index 2ed32f083..75399f7f1 100644 --- a/slsReceiverSoftware/src/GeneralData.h +++ b/slsReceiverSoftware/src/GeneralData.h @@ -444,10 +444,6 @@ class Mythen3Data : public GeneralData { * @param tgEnable ten giga enable */ virtual void SetNumberofCounters(const int n, const int dr, bool tgEnable) { - if (n < 1 || n > 3) { - throw sls::RuntimeError("Invalid number of counters " + - std::to_string(n)); - } ncounters = n; nPixelsX = NCHAN * ncounters; LOG(logINFO) << "nPixelsX: " << nPixelsX; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index c697ca036..3f8f74077 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -1624,17 +1624,19 @@ uint32_t Implementation::getCounterMask() const { void Implementation::setCounterMask(const uint32_t i) { if (counterMask != i) { - counterMask = i; - - if (myDetectorType == MYTHEN3) { - int ncounters = __builtin_popcount(i); - generalData->SetNumberofCounters(ncounters, dynamicRange, - tengigaEnable); - // to update npixelsx, npixelsy in file writer - for (const auto &it : dataProcessor) - it->SetPixelDimension(); - SetupFifoStructure(); + int ncounters = __builtin_popcount(i); + if (ncounters < 1 || ncounters > 3) { + throw sls::RuntimeError("Invalid number of counters " + + std::to_string(ncounters) + + ". Expected 1-3."); } + counterMask = i; + generalData->SetNumberofCounters(ncounters, dynamicRange, + tengigaEnable); + // to update npixelsx, npixelsy in file writer + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + SetupFifoStructure(); } LOG(logINFO) << "Counter mask: " << sls::ToStringHex(counterMask); int ncounters = __builtin_popcount(counterMask);