Skip to content

Tutorial 4: Simple pipeline with NB

Jin Heo edited this page Dec 16, 2023 · 2 revisions

How to run

$ cd FlexPipe/examples
$ bash 4_rtp_pipeline_non_blocking.sh

In this tutorial, by using the given SourceKernel and SinkKernelNB (with non-blocking input), we create a pipeline. The pipeline topology looks below.

|Source|[o1]------>[i1, NB]|Sink|

where NB: Non-blocking

Port Registration by Kernel Developer

/* examples/sample_kernels.h */
class SinkKernelNB : public flexpipe::Kernel
{
public:
  SinkKernelNB(string id) : flexpipe::Kernel(id)
  {
    setName("SinkKernelNB");
    portManager.registerInPortTag("i1", flexpipe::PortDependency::NONBLOCKING,
                                  flexpipe::deserializeDefault<MsgType>);
    frequencyManager.setFrequency(1);
  }

  ~SinkKernelNB() {}

  raft::kstatus run() override
  {
    MsgType *msg = portManager.getInput<MsgType>("i1");

    if(msg != nullptr)
    {
      ...
    }
    else printf("SinkKernelNB did not get any input...\n");

    portManager.freeInput("i1", msg);
    frequencyManager.adjust();

    return raft::proceed;
  }
};

In the sink kernel, the single input port of "i1" is registered as non-blocking. This means the kernel is not executed by this blocking input, and its execution is governed by the desired execution frequency which can be set by both kernel developer and user. Since there is a case where the kernel runs without the input, the input should be checked, and its functionality implementation should address both cases (with/without input).

Port Activation by Kernel User

As the pipeline topology is the same with the previous tutorial, the port activation and pipeline creation are the same.