Ensure you have a DFM Db backup before upgrading then you can proceed directly either to 5.0.2 or 5.1 from 4.x.
If you were hitting bug 439756, the background post-upgrade processing could take some time to complete as the 5.X code will automatically run the workaround after a successful upgrade as well as on a regular basis afterwards.
OC UM Core 5.1 will split your DFM server into either 7mode or clustered mode, so if you have a mixed environment be aware that you will have to make that decision during the upgrade.