Files
Jungfraujoch/acquisition_device/HLSSimulatedDevice.h
T
leonarski_fandClaude Opus 4.8 040cdeacf1 acquisition_device: give each device sole ownership of its buffers
The base AcquisitionDevice no longer allocates or frees frame buffers;
buffer_device is now just a non-owning view of addresses. Each subclass
owns its backing memory and the matching lifecycle:

- PCIExpressDevice mmap's the kernel DMA buffers and munmap's them in its
  own destructor (and on ctor failure), symmetric with MapKernelBuffer.
- HLSSimulatedDevice owns plain zeroed heap buffers it points
  buffer_device into, declared before the HLSDevice so they outlive the
  action thread that writes them. The buffers are page-aligned to match
  the real device's kernel DMA buffers - the modelled AXI datamover and
  FPGAIntegrationTest require aligned output buffers.

This drops the NUMA/mmap dance from the simulated path (not
performance-critical) - removing libnuma from acquisition_device - and
replaces the base-class cleanup that had to guess the allocation
strategy with a single clear owner per device.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 19:18:32 +02:00

50 lines
2.6 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <thread>
#include "../common/DiffractionExperiment.h"
#include "../fpga/hls_simulation/HLSDevice.h"
#include "FPGAAcquisitionDevice.h"
class HLSSimulatedDevice : public FPGAAcquisitionDevice {
// Owns the simulated frame buffers. Plain heap (this path is not performance-critical, so no
// NUMA placement and no mmap), but page-aligned (4 KiB) to match the real device's kernel DMA
// buffers - more than enough for the data path's alignment needs (AXI datamover 64 B,
// FPGAIntegrationTest 128 B). Declared before `device` so the buffers outlive the HLSDevice
// action thread that writes into them; buffer_device points into these.
struct alignas(4096) FrameBuffer { uint8_t data[FPGA_BUFFER_LOCATION_SIZE]; };
std::vector<std::unique_ptr<FrameBuffer>> buffers;
std::unique_ptr<HLSDevice> device;
void HW_ReadActionRegister(DataCollectionConfig *job) override;
void HW_WriteActionRegister(const DataCollectionConfig *job) override;
void FPGA_StartAction(const DiffractionExperiment &experiment) override;
void FPGA_EndAction() override;
bool HW_IsIdle() const override;
bool HW_ReadMailbox(uint32_t *values) override;
bool HW_SendWorkRequest(uint32_t handle) override;
void HW_LoadCalibration(const LoadCalibrationConfig &config) override;
void HW_SetSpotFinderParameters(const SpotFinderParameters &params) override;
void HW_RunInternalGenerator(const FrameGeneratorConfig &config) override;
public:
HLSSimulatedDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules);
~HLSSimulatedDevice() override = default;
void CreateJFPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
uint32_t module_number, const uint16_t *data, int8_t adjust_axis = 0, uint8_t user = 0);
void CreateJFPackets(const DiffractionExperiment& experiment, uint64_t frame_number_0, uint64_t frames,
uint32_t module_number, const uint16_t *data);
void CreateEIGERPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
uint32_t module_number, uint32_t col, uint32_t row,
const uint16_t *data);
void CreateXfelBunchIDPacket(double bunchid, uint32_t event_code);
void CreateFinalPacket(const DiffractionExperiment& experiment);
DataCollectionStatus GetDataCollectionStatus() const override;
void Cancel() override;
DeviceStatus GetDeviceStatus() const override;
};