Skip to content

Commit

Permalink
make mpd_plugin.h C style & fix some lint warnings (Xilinx#2190)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhz authored and sonals committed Oct 4, 2019
1 parent 97569c6 commit e208897
Show file tree
Hide file tree
Showing 14 changed files with 520 additions and 299 deletions.
293 changes: 196 additions & 97 deletions src/runtime_src/core/pcie/tools/cloud-daemon/aws/aws_dev.cpp

Large diffs are not rendered by default.

50 changes: 28 additions & 22 deletions src/runtime_src/core/pcie/tools/cloud-daemon/aws/aws_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ class AwsDev
AwsDev(size_t index, const char *logfileName);
~AwsDev();

int awsGetIcap(std::unique_ptr<xcl_pr_region> &resp);
int awsGetSensor(std::unique_ptr<xcl_sensor> &resp);
int awsGetBdinfo(std::unique_ptr<xcl_board_info> &resp);
int awsGetMig(std::unique_ptr<std::vector<char>> &resp, size_t &resp_len);
int awsGetFirewall(std::unique_ptr<xcl_mig_ecc> &resp);
int awsGetDna(std::unique_ptr<xcl_dna> &resp);
int awsGetSubdev(std::unique_ptr<std::vector<char>> &resp, size_t &resp_len);
int awsGetIcap(xcl_pr_region *resp);
int awsGetSensor(xcl_sensor *resp);
int awsGetBdinfo(xcl_board_info *resp);
int awsGetMig(char *resp, size_t resp_len);
int awsGetFirewall(xcl_mig_ecc *resp);
int awsGetDna(xcl_dna *resp);
int awsGetSubdev(char *resp, size_t resp_len);
// Bitstreams
int awsLoadXclBin(const xclBin *&buffer);
int awsLoadXclBin(const xclBin *buffer);
//int xclBootFPGA();
int awsResetDevice();
int awsReClock2(xclmgmt_ioc_freqscaling *&obj);
int awsReClock2(const xclmgmt_ioc_freqscaling *obj);
int awsLockDevice();
int awsUnlockDevice();
int awsProgramShell();
int awsReadP2pBarAddr(const xcl_mailbox_p2p_bar_addr *addr);
int awsUserProbe(xcl_mailbox_conn_resp *resp);
bool isGood();
private:
const int mBoardNumber;
Expand All @@ -87,17 +90,20 @@ class AwsDev
#endif
};

int get_remote_msd_fd(size_t index, int& fd);
int awsLoadXclBin(size_t index, const axlf *&xclbin);
int awsGetIcap(size_t index, std::unique_ptr<xcl_pr_region> &resp);
int awsGetSensor(size_t index, std::unique_ptr<xcl_sensor> &resp);
int awsGetBdinfo(size_t index, std::unique_ptr<xcl_board_info> &resp);
int awsGetMig(size_t index, std::unique_ptr<std::vector<char>> &resp, size_t &resp_len);
int awsGetFirewall(size_t index, std::unique_ptr<xcl_mig_ecc> &resp);
int awsGetDna(size_t index, std::unique_ptr<xcl_dna> &resp);
int awsGetSubdev(size_t index, std::unique_ptr<std::vector<char>> &resp, size_t &resp_len);
int awsLockDevice(size_t index);
int awsUnlockDevice(size_t index);
int awsResetDevice(size_t index);
int awsReClock2(size_t index, struct xclmgmt_ioc_freqscaling *&obj);
int get_remote_msd_fd(size_t index, int* fd);
int awsLoadXclBin(size_t index, const axlf *xclbin, int *resp);
int awsGetIcap(size_t index, xcl_pr_region *resp);
int awsGetSensor(size_t index, xcl_sensor *resp);
int awsGetBdinfo(size_t index, xcl_board_info *resp);
int awsGetMig(size_t index, char *resp, size_t resp_len);
int awsGetFirewall(size_t index, xcl_mig_ecc *resp);
int awsGetDna(size_t index, xcl_dna *resp);
int awsGetSubdev(size_t index, char *resp, size_t resp_len);
int awsLockDevice(size_t index, int *resp);
int awsUnlockDevice(size_t index, int *resp);
int awsResetDevice(size_t index, int *resp);
int awsReClock2(size_t index, const xclmgmt_ioc_freqscaling *obj, int *resp);
int awsUserProbe(size_t index, xcl_mailbox_conn_resp *resp);
int awsProgramShell(size_t index, int *resp);
int awsReadP2pBarAddr(size_t index, const xcl_mailbox_p2p_bar_addr *addr, int *resp);
#endif
17 changes: 9 additions & 8 deletions src/runtime_src/core/pcie/tools/cloud-daemon/azure/azure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int init(mpd_plugin_callbacks *cbs)
// hook functions
cbs->mpc_cookie = NULL;
cbs->get_remote_msd_fd = get_remote_msd_fd;
cbs->load_xclbin = azureLoadXclBin;
cbs->mb_req.load_xclbin = azureLoadXclBin;
ret = 0;
}
syslog(LOG_INFO, "azure mpd plugin init called: %d\n", ret);
Expand All @@ -88,16 +88,16 @@ void fini(void *mpc_cookie)
* we are going to handle mailbox ourself, no comm channel is required.
* so just return -1 to the fd
* Input:
* d: dbdf of the user PF
* index: index of the user PF
* Output:
* fd: socket handle of the communication channel
* Return value:
* 0: success
* 1: failure
*/
int get_remote_msd_fd(size_t index, int& fd)
int get_remote_msd_fd(size_t index, int* fd)
{
fd = -1;
*fd = -1;
return 0;
}

Expand All @@ -108,15 +108,16 @@ int get_remote_msd_fd(size_t index, int& fd)
* index: index of the FPGA device
* xclbin: the fake xclbin file
* Output:
* none
* resp: int as response msg
* Return value:
* 0: success
* others: error code
*/
int azureLoadXclBin(size_t index, const axlf *&xclbin)
int azureLoadXclBin(size_t index, const axlf *xclbin, int *resp)
{
AzureDev d(index);
return d.azureLoadXclBin(xclbin);
*resp = d.azureLoadXclBin(xclbin);
return 0;
}

//azure specific parts
Expand All @@ -143,7 +144,7 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use
return size * nmemb;
}

int AzureDev::azureLoadXclBin(const xclBin *&buffer)
int AzureDev::azureLoadXclBin(const xclBin *buffer)
{
char *xclbininmemory = reinterpret_cast<char*> (const_cast<xclBin*> (buffer));
if (memcmp(xclbininmemory, "xclbin2", 8) != 0)
Expand Down
6 changes: 3 additions & 3 deletions src/runtime_src/core/pcie/tools/cloud-daemon/azure/azure.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AzureDev
~AzureDev();

// Bitstreams
int azureLoadXclBin(const xclBin *&buffer);
int azureLoadXclBin(const xclBin *buffer);
static std::string get_wireserver_ip()
{
const std::string config("/opt/xilinx/xrt/etc/mpd.conf");
Expand Down Expand Up @@ -100,8 +100,8 @@ struct write_unit {
const char *uptr;
size_t sizeleft;
};
int get_remote_msd_fd(size_t index, int& fd);
int azureLoadXclBin(size_t index, const axlf *&xclbin);
int get_remote_msd_fd(size_t index, int* fd);
int azureLoadXclBin(size_t index, const axlf *xclbin, int *resp);
static size_t read_callback(void *contents, size_t size,
size_t nmemb, void *userp);
static size_t WriteCallback(void *contents, size_t size,
Expand Down
50 changes: 47 additions & 3 deletions src/runtime_src/core/pcie/tools/cloud-daemon/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <unistd.h>
#include <strings.h>
#include <algorithm>
#include <iostream>
#include <exception>
#include <dlfcn.h>

#include "common.h"
Expand Down Expand Up @@ -77,7 +79,10 @@ size_t getMailboxMsgSize(const pcieFunc& dev, int mbxfd)

// This read is expected to fail w/ errno == EMSGSIZE
// However, the real msg size should be filled out by driver.
if (read(mbxfd, swmsg->data(), swmsg->size()) >= 0 || errno != EMSGSIZE) {
if (int n = read(mbxfd, swmsg->data(), swmsg->size()) >= 0) {
dev.log(LOG_ERR, "Unexpected %d bytes read from sw mailbox", n);
return 0;
} else if (errno != EMSGSIZE) {
dev.log(LOG_ERR, "can't read sw_chan from mailbox, %m");
return 0;
}
Expand Down Expand Up @@ -261,13 +266,52 @@ void Common::postStop()
closelog();
}

Common::Common(std::string &name, std::string &plugin_path) :
Common::Common(std::string &name, std::string &plugin_path, bool for_user) :
name(name), plugin_path(plugin_path)
{
total = pcidev::get_dev_total();
total = pcidev::get_dev_total(for_user);
plugin_handle = nullptr;
}

Common::~Common()
{
}

//class Sw_mb_container
char* Sw_mb_container::get_payload_buf()
{
return processed_->payloadData();
}

std::unique_ptr<sw_msg> Sw_mb_container::get_response()
{
if (hook_ == nullptr)
*((int *)get_payload_buf()) = -ENOTSUP;
else
hook_(); //TODO check get_peer_data failure
return std::move(processed_);
}

void Sw_mb_container::set_hook(std::function<void()> hook)
{
hook_ = hook;
}

Sw_mb_container::Sw_mb_container(size_t respLen, uint64_t respID) :
hook_(nullptr)
{
try {
/*
* Build the sw_msg without payload filled yet. The buffer of the payload
* will be passed to and filled by the hook function
*/
processed_ = std::make_unique<sw_msg>(respLen, respID, XCL_MB_REQ_FLAG_RESPONSE);
} catch (std::exception &e) {
std::cout << "Sw_mb_container: " << e.what() << std::endl;
throw;
}
}

Sw_mb_container::~Sw_mb_container()
{
}
16 changes: 15 additions & 1 deletion src/runtime_src/core/pcie/tools/cloud-daemon/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mutex>
#include <condition_variable>
#include <queue>
#include <functional>
#include "pciefunc.h"
#include "sw_msg.h"
#include "core/pcie/driver/linux/include/mailbox_proto.h"
Expand Down Expand Up @@ -74,7 +75,7 @@ class Common;
class Common
{
public:
Common(std::string &name, std::string &plugin_path);
Common(std::string &name, std::string &plugin_path, bool for_user);
~Common();
void *plugin_handle;
size_t total;
Expand All @@ -88,4 +89,17 @@ class Common
std::string name;
std::string plugin_path;
};

class Sw_mb_container
{
public:
Sw_mb_container(size_t respLen, uint64_t respID);
~Sw_mb_container();
std::unique_ptr<sw_msg> get_response();
char* get_payload_buf();
void set_hook(std::function<void()> hook);
private:
std::unique_ptr<sw_msg> processed_;
std::function<void()> hook_;
};
#endif // COMMON_H
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int init(mpd_plugin_callbacks *cbs)
// hook functions
cbs->mpc_cookie = NULL;
cbs->get_remote_msd_fd = get_remote_msd_fd;
cbs->load_xclbin = xclLoadXclBin;
cbs->mb_req.load_xclbin = xclLoadXclBin;
ret = 0;
}
syslog(LOG_INFO, "container mpd plugin init called: %d\n", ret);
Expand All @@ -84,16 +84,16 @@ void fini(void *mpc_cookie)
* we are going to handle mailbox ourself, no comm channel is required.
* so just return -1 to the fd
* Input:
* d: dbdf of the user PF
* index: index of the user PF
* Output:
* fd: socket handle of the communication channel
* Return value:
* 0: success
* 1: failure
*/
int get_remote_msd_fd(size_t index, int& fd)
int get_remote_msd_fd(size_t index, int* fd)
{
fd = -1;
*fd = -1;
return 0;
}

Expand All @@ -104,20 +104,23 @@ int get_remote_msd_fd(size_t index, int& fd)
* index: index of the FPGA device
* xclbin: the fake xclbin file
* Output:
* none
* resp: int as response msg
* Return value:
* 0: success
* others: error code
*/
int xclLoadXclBin(size_t index, const axlf *&xclbin)
int xclLoadXclBin(size_t index, const axlf *xclbin, int *resp)
{
int ret = -1;
Container d(index);
if (!d.isGood())
return 1;
return d.xclLoadXclBin(xclbin);
if (d.isGood()) {
*resp = d.xclLoadXclBin(xclbin);
ret = 0;
}
return ret;
}

int Container::xclLoadXclBin(const xclBin *&buffer)
int Container::xclLoadXclBin(const xclBin *buffer)
{
/*
* This file is delivered by default not to provide xclbin protection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Container
~Container();

// Bitstreams
int xclLoadXclBin(const xclBin *&buffer);
int xclLoadXclBin(const xclBin *buffer);
bool isGood();
private:
/*
Expand All @@ -57,6 +57,6 @@ class Container
std::vector<char> read_file(const char *filename);
};

int get_remote_msd_fd(size_t index, int& fd);
int xclLoadXclBin(size_t index, const axlf *&xclbin);
int get_remote_msd_fd(size_t index, int* fd);
int xclLoadXclBin(size_t index, const axlf *xclbin, int *resp);
#endif
Loading

0 comments on commit e208897

Please sign in to comment.