I would like to disable the CPU cache of the Nvidia AGX Xavier.
I've tried to use menuconfig to control the cache but it seems not working on this system. Then I tried to use ASM, and I got an error ' illegal instruction (core dumped )'.
#include <stdio.h>
#include <string.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
void L1_off(void){
__asm__(
"mrs x1, sctlr_el1;" // read SCTLR_EL1
"ldr x1, = 0xefff;"
"and x11, x11, x1;" // turn off bit 12 and store into R1 0xefff
"msr sctlr_el1, x11;"); // restore R1 into SCTLR_EL1
}
void L1_on(void){
__asm__("mrs x11, sctlr_el1;"
"ldr x2, = 0x1000;"
"orr x11, x11, x2;" // turn on bit 12
"msr sctlr_el1, x11;");
}
int main(void){
L1_off();
//L1_on();
return 0;
}
Error message: illegal instruction (core dumped )
Related
first, thanks for reading.
now i am trying to do remove floor in the point cloud data,
this is a code that i wrote to remove the floor point cloud.
#include <iostream>
#include <cmath>
#include <vector>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <velodyne_pointcloud/point_types.h>
#include <pcl/common/common.h>
#include <pcl/common/centroid.h>
#include <pcl/common/transforms.h>
#include <pcl/console/parse.h>
#include <set>
#include <pcl/io/pcd_io.h>
#include <boost/format.hpp>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/passthrough.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/segmentation/sac_segmentation.h>
struct VelodynePointXYZIRT
{
PCL_ADD_POINT4D
PCL_ADD_INTENSITY;
uint16_t ring;
float time;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
} EIGEN_ALIGN16;
POINT_CLOUD_REGISTER_POINT_STRUCT (VelodynePointXYZIRT,
(float, x, x) (float, y, y) (float, z, z) (float, intensity, intensity)
(uint16_t, ring, ring) (float, time, time)
)
ros::Publisher pub1;
using PointXYZIRT = VelodynePointXYZIRT;
void help (const sensor_msgs::PointCloud2ConstPtr& scan)
{
// Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
pcl::PointCloud<VelodynePointXYZIRT>::Ptr cloud(new pcl::PointCloud<VelodynePointXYZIRT>());
pcl::fromROSMsg (*scan, *cloud);
pcl::ModelCoefficients coefficients;
pcl::PointIndices inliers;
// Create the segmentation object
pcl::SACSegmentation< pcl::PointCloud<PointXYZIRT>> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (0.01);
seg.setInputCloud (cloud.makeShared ());
seg.segment (inliers, coefficients);
// Publish the model coefficients
pcl_msgs::ModelCoefficients ros_coefficients;
pcl_conversions::fromPCL(coefficients, ros_coefficients);
pub1.publish (ros_coefficients);
}
int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "my_pcl_tutorial");
ros::NodeHandle nh;
// Create a ROS subscriber for the input point cloud
ros::Subscriber sub = nh.subscribe ("input", 1, help);
// Create a ROS publisher for the output point cloud
//#pub1 = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);
pub1 = nh.advertise<pcl_msgs::ModelCoefficients> ("output", 1);
// Spin
ros::spin ();
}
as i have to put the ring data in the code, so i made the struct for defining the velodyne lidar,
but when i catkin_make in the ros,
this error comes,
error: ‘pcl::PointCloud<VelodynePointXYZIRT>::Ptr {aka class boost::shared_ptr<pcl::PointCloud<VelodynePointXYZIRT> >}’ has no member named ‘makeShared’
seg.setInputCloud (cloud.makeShared ());
is there a method that i visualize the data?
my reference for making the code is this site,https://adioshun.gitbooks.io/pcl-tutorial/content/part-1/part01-chapter05/part01-chapter05-practice.html
and my previous code to transform the lidar data, i used these code to make my own.....
#include <iostream>
#include <cmath>
#include <vector>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <velodyne_pointcloud/point_types.h>
#include <pcl/common/common.h>
#include <pcl/common/centroid.h>
#include <pcl/common/transforms.h>
#include <pcl/console/parse.h>
#include <set>
#include <pcl/io/pcd_io.h>
#include <boost/format.hpp>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/passthrough.h>
#define PI 3.14159265359
using namespace std;
struct VelodynePointXYZIRT
{
PCL_ADD_POINT4D
PCL_ADD_INTENSITY;
uint16_t ring;
float time;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
} EIGEN_ALIGN16;
POINT_CLOUD_REGISTER_POINT_STRUCT (VelodynePointXYZIRT,
(float, x, x) (float, y, y) (float, z, z) (float, intensity, intensity)
(uint16_t, ring, ring) (float, time, time)
)
ros::Publisher pub1;
float theta_r = 45* M_PI/ 180; // 라디안 각도로 회전 (180도 회전)
using PointXYZIRT = VelodynePointXYZIRT;
void input(const sensor_msgs::PointCloud2ConstPtr& scan)
{
// Msg to pointcloud
pcl::PointCloud<VelodynePointXYZIRT>::Ptr cloud(new pcl::PointCloud<VelodynePointXYZIRT>());
pcl::fromROSMsg(*scan,*cloud); // ros msg 에서 pcl cloud 데이터로 변환
//회전변환행렬
Eigen::Matrix4f transform_1 = Eigen::Matrix4f::Identity();
// Define a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix)
transform_1 (0,0) = std::cos (theta_r);
transform_1 (0,2) = std::sin(theta_r);
transform_1 (2,0) = -sin (theta_r);
transform_1 (2,2) = std::cos (theta_r);
// (row, column)
// Executing the transformation
pcl::PointCloud<VelodynePointXYZIRT>::Ptr transformed_cloud (new pcl::PointCloud<PointXYZIRT>());
pcl::transformPointCloud (*cloud, *transformed_cloud, transform_1);
pcl::PCLPointCloud2 cloud_p;
pcl::toPCLPointCloud2(*transformed_cloud, cloud_p);
sensor_msgs::PointCloud2 output;
pcl_conversions::fromPCL(cloud_p, output);
output.header.frame_id = "velodyne";
pub1.publish(output);
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "input");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("vlp202", 100, input);
pub1 = nh.advertise<sensor_msgs::PointCloud2> ("vlp203", 100);
ros::spin();
}
//if you have to make your own type of custum point type in the pcl, you can see this one to see how to code it !!
// also the ring data that you have to use is from the lio_sam, image projection.cpp
so for the abstract,
i want to remove floor point cloud data in recorded bag,
so i made some code to remove floor data
The "cloud" object is already a shared pointer. Remove makeShared call:
seg.setInputCloud (cloud.makeShared ());
to
seg.setInputCloud (cloud);
For visualization you could publish over a topic the result as ros message and visualize it with rviz.
Apple says that on ARM64 Macs memory regions can have either write or execution permissions for a thread. How would someone find out the current permissions for a memory region for a thread in lldb? I have tried 'memory region ' but that returns rwx. I am working on a Just-In-Time compiler that will run on my M1 Mac. For testing I made a small simulation of a Just-In-Time compiler.
#include <cstdio>
#include <sys/mman.h>
#include <pthread.h>
#include <libkern/OSCacheControl.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
size_t size = 1024 * 1024 * 640;
int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT;
int fd = -1;
int offset = 0;
unsigned *addr = 0;
// allocate a mmap'ed region of memory
addr = (unsigned *)mmap(0, size, prot, flags, fd, offset);
if (addr == MAP_FAILED){
printf("failure detected\n");
exit(-1);
}
pthread_jit_write_protect_np(0);
// Write instructions to the memory
addr[0] = 0xd2800005; // mov x5, #0x0
addr[1] = 0x910004a5; // add x5, x5, #0x1
addr[2] = 0x17ffffff; // b <address>
pthread_jit_write_protect_np(1);
sys_icache_invalidate(addr, size);
// Execute the code
int(*f)() = (int (*)()) addr;
(*f)();
return 0;
}
Once the assembly instructions start executing thru the (*f)() call, I can pause execution in Xcode and type
memory region {address of instructions}
into the debugger. For some reason it keeps returning 'rwx'. Am I using the right command or could this be a bug with lldb?
When I run your little program on a Mac where I can poke around (I'm on x86_64 but it shouldn't matter, I don't actually need to run the instructions...) I see in lldb:
Process 43209 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100003f20 protectit`main at protectit.cpp:31
28 addr[2] = 0x17ffffff; // b <address>
29
30 pthread_jit_write_protect_np(1);
-> 31 sys_icache_invalidate(addr, size);
^
32
33 // Execute the code
34 int(*f)() = (int (*)()) addr;
Target 0: (protectit) stopped.
(lldb) memory region addr
[0x0000000101000000-0x0000000129000000) rwx
which is as you report. I then double-checked with vmmap:
> vmmap 43209 0x0000000101000000
0x101000000 is in 0x101000000-0x129000000; bytes after start: 0 bytes before end: 671088639
REGION TYPE START - END [ VSIZE RSDNT DIRTY SWAP] PRT/MAX SHRMOD PURGE REGION DETAIL
MALLOC_SMALL 100800000-101000000 [ 8192K 8K 8K 0K] rw-/rwx SM=PRV MallocHelperZone_0x1001c4000
---> VM_ALLOCATE 101000000-129000000 [640.0M 4K 4K 0K] rwx/rwx SM=PRV
GAP OF 0x5ffed7000000 BYTES
MALLOC_NANO 600000000000-600008000000 [128.0M 88K 88K 0K] rw-/rwx SM=PRV DefaultMallocZone_0x1001f1000
so vmmap agrees with lldb that the region is rwx.
Whatever pthread_jit_write_protect_np is doing, it doesn't seem to be changing the underlying memory region protections.
I found out the answer to my question is to read an undocumented Apple register called S3_6_c15_c1_5.
This code reads the raw value from the register:
// Returns the S3_6_c15_c1_5 register's value
uint64_t read_S3_6_c15_c1_5_register(void)
{
uint64_t v;
__asm__ __volatile__("isb sy\n"
"mrs %0, S3_6_c15_c1_5\n"
: "=r"(v)::"memory");
return v;
}
This code tells you what your thread's current mode is:
// Returns the mode for a thread.
// Returns "Executable" or "Writable".
// Remember to free() the value returned by this function.
char *get_thread_mode()
{
uint64_t value = read_S3_6_c15_c1_5_register();
char *return_value = (char *) malloc(50);
switch(value)
{
case 0x2010000030300000:
sprintf(return_value, "Writable");
break;
case 0x2010000030100000:
sprintf(return_value, "Executable");
break;
default:
sprintf(return_value, "Unknown state: %llx", value);
}
return return_value;
}
This is a small test program to demonstrate these two functions:
int main(int argc, char *argv[]) {
pthread_jit_write_protect_np(1);
printf("Thread's mode: %s\n", get_thread_mode());
// The mode is Executable
pthread_jit_write_protect_np(0);
printf("Thread's mode: %s\n", get_thread_mode());
// The mode is Writable
return 0;
}
I want to protect a memory region from writing. I've configured MPU, but it is not generating any faults.
The base address of the region that I want to protect is 0x20000000. The region size is 64 bytes.
Here's a compiling code that demonstrates the issue.
#define MPU_CTRL (*((volatile unsigned long*) 0xE000ED94))
#define MPU_RNR (*((volatile unsigned long*) 0xE000ED98))
#define MPU_RBAR (*((volatile unsigned long*) 0xE000ED9C))
#define MPU_RASR (*((volatile unsigned long*) 0xE000EDA0))
#define SCB_SHCSR (*((volatile unsigned long*) 0xE000ED24))
void Registers_Init(void)
{
MPU_RNR = 0x00000000; // using region 0
MPU_RBAR = 0x20000000; // base address is 0x20000000
MPU_RASR = 0x0700110B; // Size is 64 bytes, no sub-regions, permission=7(ro,ro), s=b=c= 0, tex=0
MPU_CTRL = 0x00000001; // enable MPU
SCB_SHCSR = 0x00010000; // enable MemManage Fault
}
void MemManage_Handler(void)
{
__asm(
"MOV R4, 0x77777777\n\t"
"MOV R5, 0x77777777\n\t"
);
}
int main(void)
{
Registers_Init();
__asm(
"LDR R0, =0x20000000\n\t"
"MOV R1, 0x77777777\n\t"
"STR R1, [R0,#0]"
);
return (1);
}
void SystemInit(void)
{
}
So, in main function, I am writing in restricted area i.e. 0x20000000, but MPU is not generating any fault and instead of calling MemManage_Handler(), it writes successfully.
This looks fine to me. Make sure your hardware have a MPU. MPU has a register called MPU_TYPE Register. This is a read-only register that tells you if you have a MPU or not. If bits 15:8 in MPU_TYPE register read 0, there's no MPU.
And never use numbers when dealing with registers. This makes it really hard for you and other person to read your code. Instead, define a number of bit masks. See tutorials on how to do that.
I am using OpenCv and OpenKinect on Ubuntu platform to access Kinect sensor. The major error is: undefined reference to `freenect_sync_get_rgb_cv' Help me to debug this error. The Source code is as given below:
#include <iostream>
#include <cv.h>
#include <opencv/highgui.h>
// OpenKinect Header files
#include <libfreenect.h>
#include <libfreenect_sync.h>
#include <libfreenect/libfreenect_cv.h>
// --- C++ ---
#include <stdio.h>
#include <fstream>
#include <vector>
#include <math.h>
#include <iostream>
#include <vector>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
char key;
// IplImage *freenect_sync_get_depth_cv(int index);
// IplImage *freenect_sync_get_rgb_cv(int index);
int main(int argc, char** argv)
{
IplImage* image = NULL;
/* create a window */
cvNamedWindow("Camera_Output", 1);
while(1) {
image = freenect_sync_get_rgb_cv(0);
// Mat image(freenect_sync_get_rgb_cv(0));
//CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
// cvCvtColor(image, image, CV_RGB2BGR); // cvLoadImage( freenect_sync_get_rgb_cv(0) )
// VideoCapture::grab
//cvCreateImage(cvSize(640, 480), 8, 4);
cvShowImage("Camera_Output", image);
if (!image) {
printf("Error: Kinect not connected?\n");
return -1;
}
key = cvWaitKey(100); //Capture Keyboard stroke
if (char(key) == 27){
break;
}
}
/* free memory */
cvDestroyWindow( "video" );
return 0;
}
The error looks like:
[100%] Building CXX object CMakeFiles/KinectRGB.dir/KinectRGB.cpp.o
Linking CXX executable KinectRGB
CMakeFiles/KinectRGB.dir/KinectRGB.cpp.o: In function `main':
KinectRGB.cpp:(.text+0x2c): undefined reference to `freenect_sync_get_rgb_cv'
collect2: error: ld returned 1 exit status
make[2]: *** [KinectRGB] Error 1
make[1]: *** [CMakeFiles/KinectRGB.dir/all] Error 2
make: *** [all] Error 2
sincos#sincos-300E4C-300E5C-300E7C:~/Desktop/OpenCV_test/KinectRead/build$
CMakeLists.txt file to Build the code is as given below:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
project(KinectRGB)
set(DEPENDENCIES OpenCV GLUT OpenGL)
message("\n")
foreach( DEP ${DEPENDENCIES} )
find_package( ${DEP} )
string( TOUPPER ${DEP} UDEP ) # Capitalize
if( ${DEP}_FOUND OR ${UDEP}_FOUND )
message("\n${DEP}_Found = TRUE\n")
endif()
find_package(Threads REQUIRED)
find_package(libfreenect REQUIRED)
include_directories("/usr/include/libusb-1.0/")
endforeach()
include_directories(
${FREENECT_INCLUDE_DIR}
${GLUT_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS}
)
add_executable(KinectRGB KinectRGB.cpp)
target_link_libraries(KinectRGB
${FREENECT_LIBRARIES}
${GLUT_LIBRARY}
${OPENGL_LIBRARIES}
${OpenCV_LIBS}
${CMAKE_THREAD_LIBS_INIT}
)
I would not recommend using IplImage. It is a primitive class type. To test whether your Kinect is working properly, run the following python script:
import freenect
import cv2
import numpy as np
from functions import *
def nothing(x):
pass
kernel = np.ones((5, 5), np.uint8)
def pretty_depth(depth):
np.clip(depth, 0, 2**10 - 1, depth)
depth >>= 2
depth = depth.astype(np.uint8)
return depth
while 1:
dst = pretty_depth(freenect.sync_get_depth()[0])#input from kinect
cv2.imshow('Video', dst)
if cv2.waitKey(1) & 0xFF == ord('b'):
break
You should see the kinect's disparity map
I am new to QNX platform, and we are porting Linux project to QNX. and found code related to shared memory creating in linux using shmget system call. but shmget not present in QNX. and I saw similar call shm_open, I don't know difference b/w both.
My straight question is like, should I use shm_open instead of shmget in QNX platform ? If yes, how ? if not, why not ?
First of all QNX does NOT support the shmget() API.
You will need to use shm_open() instead.
Below is a sample program from online QNX documentation
that demonstrates the proper use of shm_open() on QNX:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mman.h>
int main( int argc, char** argv )
{
int fd;
unsigned* addr;
/*
* In case the unlink code isn't executed at the end
*/
if( argc != 1 ) {
shm_unlink( "/bolts" );
return EXIT_SUCCESS;
}
/* Create a new memory object */
fd = shm_open( "/bolts", O_RDWR | O_CREAT, 0777 );
if( fd == -1 ) {
fprintf( stderr, "Open failed:%s\n",
strerror( errno ) );
return EXIT_FAILURE;
}
/* Set the memory object's size */
if( ftruncate( fd, sizeof( *addr ) ) == -1 ) {
fprintf( stderr, "ftruncate: %s\n",
strerror( errno ) );
return EXIT_FAILURE;
}
/* Map the memory object */
addr = mmap( 0, sizeof( *addr ),
PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0 );
if( addr == MAP_FAILED ) {
fprintf( stderr, "mmap failed: %s\n",
strerror( errno ) );
return EXIT_FAILURE;
}
printf( "Map addr is 0x%08x\n", addr );
/* Write to shared memory */
*addr = 1;
/*
* The memory object remains in
* the system after the close
*/
close( fd );
/*
* To remove a memory object
* you must unlink it like a file.
*
* This may be done by another process.
*/
shm_unlink( "/bolts" );
return EXIT_SUCCESS;
}
Hope this helps.